pythread


Namepythread JSON
Version 1.5.0 PyPI version JSON
download
home_pagehttps://github.com/DedInc/pythread
SummaryA Python library providing a user-friendly interface for managing both synchronous and asynchronous threads.
upload_time2024-01-11 05:53:23
maintainer
docs_urlNone
authorMaehdakvan
requires_python>=3.0
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pythread ๐Ÿงต

A Python library providing a user-friendly interface for managing both synchronous and asynchronous threads.

## Description ๐Ÿ“š

**pythread** is a dual-threading Python library crafted to streamline the creation and management of threads in Python applications. It offers two distinct managers: 

- **SyncThreadManager**: Handles classic synchronous threads for executing blocking operations.
- **AsyncThreadManager**: Manages asynchronous tasks to run coroutines in a non-blocking fashion.

With **pythread**, starting, stopping, and supervising the life cycle of threads and async tasks becomes effortless, enhancing the readability and resilience of your code.

## Features โœจ

- Initiate and terminate threads/tasks by name or reference.
- Accommodates additional arguments for threads/tasks.
- Simple management of thread/task lifecycle.
- Suitable for both sync and async implementations.

## Installation ๐Ÿ“ฅ

To get started with **pythread**, run:

```sh
pip install pythread
```

## Use Cases ๐Ÿ”ง

- Conducting background tasks like I/O operations, processing data, or scheduled tasks.
- Handling multiple network connections in parallel.
- Implementing producer-consumer patterns using thread-safe queues.
- Crafting a basic task scheduler for time-based task execution.

## Documentation ๐Ÿ“„

### SyncThreadManager

Facilitates the creation of synchronous threads for running functions with specific delays.

```python
# Initialize the SyncThreadManager
manager = SyncThreadManager()

# Function to run in a separate thread
def print_message(message):
    print(f"Thread message: {message}")

# Start a new thread with a specific action and delay
thread = manager.start_thread(name='PrinterThread', func=print_message, delay=1, 
    message='Hello from SyncThread!'
)

# Stop the thread using its name
manager.stop_thread('PrinterThread')

# Stop the thread using the thread object
manager.stop_thread(thread)
```

### AsyncThreadManager

Enables the execution of async coroutines concurrently.

```python
import asyncio
from pythread import AsyncThreadManager

# Initialize the AsyncThreadManager
manager = AsyncThreadManager()

# Example coroutine function
async def async_print_message(message):
    print(f"Async message: {message}")

# Start and run an async task
loop = asyncio.get_event_loop()
task = loop.run_until_complete(manager.start_task(name='AsyncPrinter', coro_func=async_print_message, message='Hello from AsyncThread!'))

# Stop the task using its name
loop.run_until_complete(manager.stop_task('AsyncPrinter'))

# Stop the task using the task object
loop.run_until_complete(manager.stop_task(task))
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/DedInc/pythread",
    "name": "pythread",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.0",
    "maintainer_email": "",
    "keywords": "",
    "author": "Maehdakvan",
    "author_email": "visitanimation@google.com",
    "download_url": "https://files.pythonhosted.org/packages/89/73/79aabc468db4598ce27e982a92b05d418c435084d5d2213295f947833572/pythread-1.5.0.tar.gz",
    "platform": null,
    "description": "# pythread \ud83e\uddf5\r\n\r\nA Python library providing a user-friendly interface for managing both synchronous and asynchronous threads.\r\n\r\n## Description \ud83d\udcda\r\n\r\n**pythread** is a dual-threading Python library crafted to streamline the creation and management of threads in Python applications. It offers two distinct managers: \r\n\r\n- **SyncThreadManager**: Handles classic synchronous threads for executing blocking operations.\r\n- **AsyncThreadManager**: Manages asynchronous tasks to run coroutines in a non-blocking fashion.\r\n\r\nWith **pythread**, starting, stopping, and supervising the life cycle of threads and async tasks becomes effortless, enhancing the readability and resilience of your code.\r\n\r\n## Features \u2728\r\n\r\n- Initiate and terminate threads/tasks by name or reference.\r\n- Accommodates additional arguments for threads/tasks.\r\n- Simple management of thread/task lifecycle.\r\n- Suitable for both sync and async implementations.\r\n\r\n## Installation \ud83d\udce5\r\n\r\nTo get started with **pythread**, run:\r\n\r\n```sh\r\npip install pythread\r\n```\r\n\r\n## Use Cases \ud83d\udd27\r\n\r\n- Conducting background tasks like I/O operations, processing data, or scheduled tasks.\r\n- Handling multiple network connections in parallel.\r\n- Implementing producer-consumer patterns using thread-safe queues.\r\n- Crafting a basic task scheduler for time-based task execution.\r\n\r\n## Documentation \ud83d\udcc4\r\n\r\n### SyncThreadManager\r\n\r\nFacilitates the creation of synchronous threads for running functions with specific delays.\r\n\r\n```python\r\n# Initialize the SyncThreadManager\r\nmanager = SyncThreadManager()\r\n\r\n# Function to run in a separate thread\r\ndef print_message(message):\r\n    print(f\"Thread message: {message}\")\r\n\r\n# Start a new thread with a specific action and delay\r\nthread = manager.start_thread(name='PrinterThread', func=print_message, delay=1, \r\n    message='Hello from SyncThread!'\r\n)\r\n\r\n# Stop the thread using its name\r\nmanager.stop_thread('PrinterThread')\r\n\r\n# Stop the thread using the thread object\r\nmanager.stop_thread(thread)\r\n```\r\n\r\n### AsyncThreadManager\r\n\r\nEnables the execution of async coroutines concurrently.\r\n\r\n```python\r\nimport asyncio\r\nfrom pythread import AsyncThreadManager\r\n\r\n# Initialize the AsyncThreadManager\r\nmanager = AsyncThreadManager()\r\n\r\n# Example coroutine function\r\nasync def async_print_message(message):\r\n    print(f\"Async message: {message}\")\r\n\r\n# Start and run an async task\r\nloop = asyncio.get_event_loop()\r\ntask = loop.run_until_complete(manager.start_task(name='AsyncPrinter', coro_func=async_print_message, message='Hello from AsyncThread!'))\r\n\r\n# Stop the task using its name\r\nloop.run_until_complete(manager.stop_task('AsyncPrinter'))\r\n\r\n# Stop the task using the task object\r\nloop.run_until_complete(manager.stop_task(task))\r\n```\r\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "A Python library providing a user-friendly interface for managing both synchronous and asynchronous threads.",
    "version": "1.5.0",
    "project_urls": {
        "Bug Tracker": "https://github.com/DedInc/pythread/issues",
        "Homepage": "https://github.com/DedInc/pythread"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "152a703e2b8f0b781beedf0ca8f88309e6554b36a36e487a49dcb711b44ffb9a",
                "md5": "18f68ee839958f2cdcd3477067013688",
                "sha256": "dd42b5570e4a4ddc0d7e434a612c4dd2307dc4f62653f83bc91b0915bf0f1eea"
            },
            "downloads": -1,
            "filename": "pythread-1.5.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "18f68ee839958f2cdcd3477067013688",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.0",
            "size": 4014,
            "upload_time": "2024-01-11T05:53:21",
            "upload_time_iso_8601": "2024-01-11T05:53:21.314910Z",
            "url": "https://files.pythonhosted.org/packages/15/2a/703e2b8f0b781beedf0ca8f88309e6554b36a36e487a49dcb711b44ffb9a/pythread-1.5.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "897379aabc468db4598ce27e982a92b05d418c435084d5d2213295f947833572",
                "md5": "22c6bdda8caa0a0c374d71b953f29de1",
                "sha256": "13cb5eb67cd216ab87b4195a3e0349061e41be04b353c93f37d7f3c36d27b911"
            },
            "downloads": -1,
            "filename": "pythread-1.5.0.tar.gz",
            "has_sig": false,
            "md5_digest": "22c6bdda8caa0a0c374d71b953f29de1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.0",
            "size": 3812,
            "upload_time": "2024-01-11T05:53:23",
            "upload_time_iso_8601": "2024-01-11T05:53:23.103560Z",
            "url": "https://files.pythonhosted.org/packages/89/73/79aabc468db4598ce27e982a92b05d418c435084d5d2213295f947833572/pythread-1.5.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-11 05:53:23",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "DedInc",
    "github_project": "pythread",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pythread"
}
        
Elapsed time: 0.20301s