Name | threadyq JSON |
Version |
1.0.0
JSON |
| download |
home_page | https://github.com/muhammedrahil/ThreadyQ |
Summary | ThreadyQ is a Python library designed to simplify and extend the capabilities of threading and queue management. This package provides an abstraction layer over Python's built-in threading and queue modules, enabling developers to create, manage, and synchronize tasks efficiently in multi-threaded applications. |
upload_time | 2024-12-11 07:17:31 |
maintainer | None |
docs_url | None |
author | Muhammed Rahil M |
requires_python | None |
license | None |
keywords |
python
threading
queue
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# ThreadyQ
`ThreadyQ` is a Python library designed to simplify and extend the capabilities of threading and queue management. This package provides an abstraction layer over Python's built-in threading and queue modules, enabling developers to create, manage, and synchronize tasks efficiently in multi-threaded applications.
`ThreadyQ` is a simple Python utility that provides a thread-safe task queue managed by a background worker thread. It enables asynchronous execution of tasks with minimal setup.
## Features
- **Thread-safe task queue**
- **Asynchronous task execution**
- **Graceful shutdown and completion handling**
- **Colored console output for responses**
---
## Requirements
This utility works with:
- Python 3.6+
---
## Installation
Copy the `ThreadyQ` class code into your project or save it as `threadyq.py`. Import it wherever needed.
---
## Usage
### Importing ThreadyQ
```python
from threadyq import ThreadyQ
```
### Creating a Task Queue
```python
# Create an instance of ThreadyQ
tq = ThreadyQ()
```
### Adding Tasks
You can add tasks to the queue using the `put_the_task` method. Each task must be a callable function.
```python
# Define a sample task
def sample_task(arg1, arg2):
print(f"Task executed with arguments: {arg1}, {arg2}")
# Add the task to the queue
tq.put_the_task(sample_task, "Hello", "World")
```
### Monitoring Tasks
You can get the number of pending tasks in the queue:
```python
print(f"Pending tasks: {tq.get_task_count()}")
```
### Waiting for All Tasks to Complete
To block the main thread until all tasks in the queue are completed:
```python
tq.join()
```
### Example
Here is a complete example:
```python
from threadyq import ThreadyQ
def sample_task(arg1, arg2):
print(f"Task executed with arguments: {arg1}, {arg2}")
# Initialize ThreadyQ
tq = ThreadyQ()
# Add tasks to the queue
tq.put_the_task(sample_task, "Hello", "World")
tq.put_the_task(sample_task, "Foo", "Bar")
# Wait for all tasks to complete
tq.join()
```
### Output
```plaintext
Task sample_task added. Current task count: 1
Task sample_task added. Current task count: 2
Task executed with arguments: Hello, World
Task executed with arguments: Foo, Bar
All tasks completed.
```
---
## Customization
### Print Colored Messages
You can customize the output of `print_response` to provide color-coded messages for success or error logs.
### Worker Daemon Mode
By default, the worker thread runs as a daemon. You can change this behavior by passing `daemon=False` while initializing `ThreadyQ`:
```python
tq = ThreadyQ(daemon=False)
```
---
## Limitations
- The worker thread doesn’t have a direct shutdown mechanism in this version. To improve it, you can implement a stop signal as shown in enhanced versions.
- It’s best suited for lightweight task management. For large-scale or complex systems, consider frameworks like Celery.
---
## Contributing
Feel free to contribute to `ThreadyQ` by submitting pull requests or reporting issues.
---
## License
This utility is open-source and free to use. Licensed under the MIT License.
Raw data
{
"_id": null,
"home_page": "https://github.com/muhammedrahil/ThreadyQ",
"name": "threadyq",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "python, threading, queue",
"author": "Muhammed Rahil M",
"author_email": "muhammedrahilmadathingal@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/98/1a/c3f49d1fb33334718ec5b50f818ba77efed5edb1469acf0064632078df72/threadyq-1.0.0.tar.gz",
"platform": null,
"description": "# ThreadyQ\r\n\r\n`ThreadyQ` is a Python library designed to simplify and extend the capabilities of threading and queue management. This package provides an abstraction layer over Python's built-in threading and queue modules, enabling developers to create, manage, and synchronize tasks efficiently in multi-threaded applications.\r\n\r\n\r\n\r\n`ThreadyQ` is a simple Python utility that provides a thread-safe task queue managed by a background worker thread. It enables asynchronous execution of tasks with minimal setup.\r\n\r\n\r\n\r\n## Features\r\n\r\n- **Thread-safe task queue**\r\n\r\n- **Asynchronous task execution**\r\n\r\n- **Graceful shutdown and completion handling**\r\n\r\n- **Colored console output for responses**\r\n\r\n\r\n\r\n---\r\n\r\n\r\n\r\n## Requirements\r\n\r\n\r\n\r\nThis utility works with:\r\n\r\n- Python 3.6+\r\n\r\n\r\n\r\n---\r\n\r\n\r\n\r\n## Installation\r\n\r\n\r\n\r\nCopy the `ThreadyQ` class code into your project or save it as `threadyq.py`. Import it wherever needed.\r\n\r\n\r\n\r\n---\r\n\r\n\r\n\r\n## Usage\r\n\r\n\r\n\r\n### Importing ThreadyQ\r\n\r\n```python\r\n\r\nfrom threadyq import ThreadyQ\r\n\r\n```\r\n\r\n\r\n\r\n### Creating a Task Queue\r\n\r\n```python\r\n\r\n# Create an instance of ThreadyQ\r\n\r\ntq = ThreadyQ()\r\n\r\n```\r\n\r\n\r\n\r\n### Adding Tasks\r\n\r\nYou can add tasks to the queue using the `put_the_task` method. Each task must be a callable function.\r\n\r\n\r\n\r\n```python\r\n\r\n# Define a sample task\r\n\r\ndef sample_task(arg1, arg2):\r\n\r\n print(f\"Task executed with arguments: {arg1}, {arg2}\")\r\n\r\n\r\n\r\n# Add the task to the queue\r\n\r\ntq.put_the_task(sample_task, \"Hello\", \"World\")\r\n\r\n```\r\n\r\n\r\n\r\n### Monitoring Tasks\r\n\r\nYou can get the number of pending tasks in the queue:\r\n\r\n```python\r\n\r\nprint(f\"Pending tasks: {tq.get_task_count()}\")\r\n\r\n```\r\n\r\n\r\n\r\n### Waiting for All Tasks to Complete\r\n\r\nTo block the main thread until all tasks in the queue are completed:\r\n\r\n```python\r\n\r\ntq.join()\r\n\r\n```\r\n\r\n\r\n\r\n### Example\r\n\r\nHere is a complete example:\r\n\r\n```python\r\n\r\nfrom threadyq import ThreadyQ\r\n\r\n\r\n\r\ndef sample_task(arg1, arg2):\r\n\r\n print(f\"Task executed with arguments: {arg1}, {arg2}\")\r\n\r\n\r\n\r\n# Initialize ThreadyQ\r\n\r\ntq = ThreadyQ()\r\n\r\n\r\n\r\n# Add tasks to the queue\r\n\r\ntq.put_the_task(sample_task, \"Hello\", \"World\")\r\n\r\ntq.put_the_task(sample_task, \"Foo\", \"Bar\")\r\n\r\n\r\n\r\n# Wait for all tasks to complete\r\n\r\ntq.join()\r\n\r\n```\r\n\r\n\r\n\r\n### Output\r\n\r\n```plaintext\r\n\r\nTask sample_task added. Current task count: 1\r\n\r\nTask sample_task added. Current task count: 2\r\n\r\nTask executed with arguments: Hello, World\r\n\r\nTask executed with arguments: Foo, Bar\r\n\r\nAll tasks completed.\r\n\r\n```\r\n\r\n\r\n\r\n---\r\n\r\n\r\n\r\n## Customization\r\n\r\n### Print Colored Messages\r\n\r\nYou can customize the output of `print_response` to provide color-coded messages for success or error logs.\r\n\r\n\r\n\r\n### Worker Daemon Mode\r\n\r\nBy default, the worker thread runs as a daemon. You can change this behavior by passing `daemon=False` while initializing `ThreadyQ`:\r\n\r\n```python\r\n\r\ntq = ThreadyQ(daemon=False)\r\n\r\n```\r\n\r\n\r\n\r\n---\r\n\r\n\r\n\r\n## Limitations\r\n\r\n- The worker thread doesn\u2019t have a direct shutdown mechanism in this version. To improve it, you can implement a stop signal as shown in enhanced versions.\r\n\r\n- It\u2019s best suited for lightweight task management. For large-scale or complex systems, consider frameworks like Celery.\r\n\r\n\r\n\r\n---\r\n\r\n\r\n\r\n## Contributing\r\n\r\nFeel free to contribute to `ThreadyQ` by submitting pull requests or reporting issues.\r\n\r\n\r\n\r\n---\r\n\r\n\r\n\r\n## License\r\n\r\nThis utility is open-source and free to use. Licensed under the MIT License.\r\n\r\n\r\n\r\n",
"bugtrack_url": null,
"license": null,
"summary": "ThreadyQ is a Python library designed to simplify and extend the capabilities of threading and queue management. This package provides an abstraction layer over Python's built-in threading and queue modules, enabling developers to create, manage, and synchronize tasks efficiently in multi-threaded applications.",
"version": "1.0.0",
"project_urls": {
"Homepage": "https://github.com/muhammedrahil/ThreadyQ"
},
"split_keywords": [
"python",
" threading",
" queue"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "469be98ed1f7399f86e816220c7512fc6a898de3dfd601216687c71516db2df8",
"md5": "38f3f2242993ee1864ec075a76a70130",
"sha256": "b78b32ad98e09bf31ecd6c28010749ca5d0fbbf5fa9dbbfd61fe59e6ef8a41c9"
},
"downloads": -1,
"filename": "threadyq-1.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "38f3f2242993ee1864ec075a76a70130",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 4735,
"upload_time": "2024-12-11T07:17:30",
"upload_time_iso_8601": "2024-12-11T07:17:30.203386Z",
"url": "https://files.pythonhosted.org/packages/46/9b/e98ed1f7399f86e816220c7512fc6a898de3dfd601216687c71516db2df8/threadyq-1.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "981ac3f49d1fb33334718ec5b50f818ba77efed5edb1469acf0064632078df72",
"md5": "0830556215adccaf21e654d840cf38e6",
"sha256": "1f97e6d327b9829069debf67eebf85acfa3276f8c5b1cb490a0269ac46813106"
},
"downloads": -1,
"filename": "threadyq-1.0.0.tar.gz",
"has_sig": false,
"md5_digest": "0830556215adccaf21e654d840cf38e6",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 4783,
"upload_time": "2024-12-11T07:17:31",
"upload_time_iso_8601": "2024-12-11T07:17:31.551407Z",
"url": "https://files.pythonhosted.org/packages/98/1a/c3f49d1fb33334718ec5b50f818ba77efed5edb1469acf0064632078df72/threadyq-1.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-11 07:17:31",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "muhammedrahil",
"github_project": "ThreadyQ",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "threadyq"
}