# CoroutineSession
`CoroutineSession` is a designed to manage and execute asyncio tasks with optional progress tracking and callbacks. It supports running tasks with a concurrency limit and batching delay.
## Features
- Add and manage asyncio tasks.
- Execute tasks with a specified maximum number of concurrent tasks.
- Delay between batches of tasks for better control over execution.
- Optional callback functions to handle task completion and progress updates.
- Progress tracking with individual task shares for better granularity.
## Installation
This class is part of a Python project and requires Python 3.7 or later. Ensure you have `pydantic` installed:
```bash
pip install simple-coroutine
```
```python
import asyncio
from simple_coroutine.manager import CoroutineSession
async def sample_task(task_id):
await asyncio.sleep(2) # Simulate a task taking some time
return f"Task {task_id} completed"
async def main():
session = CoroutineSession(
max_concurrent_tasks=2,
batch_delay=5,
callback=lambda index, result: print(f"Task {index} result: {result}"),
progress_callback=lambda index, progress, total: print(f"Task {index} progress: {progress}, Total: {total}")
)
tasks = [sample_task(i) for i in range(5)]
session.add_task_set(tasks)
results = await session.run_tasks()
print("All tasks completed:", results)
async for progress in session.progress_generator():
print(f"Progress: {progress}%")
if __name__ == "__main__":
asyncio.run(main())
```
Raw data
{
"_id": null,
"home_page": "https://github.com/hragbalian/coroutine_manager",
"name": "simple-coroutine",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.11",
"maintainer_email": null,
"keywords": "coroutines, async, asyncio, callback",
"author": "Hrag Balian",
"author_email": "hrag.balian@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/61/e1/07493f6706400d7beff8648378b8b324ee44f6b1deeb4fb15438eff16208/simple_coroutine-0.1.5.tar.gz",
"platform": null,
"description": "# CoroutineSession\n\n`CoroutineSession` is a designed to manage and execute asyncio tasks with optional progress tracking and callbacks. It supports running tasks with a concurrency limit and batching delay.\n\n## Features\n\n- Add and manage asyncio tasks.\n- Execute tasks with a specified maximum number of concurrent tasks.\n- Delay between batches of tasks for better control over execution.\n- Optional callback functions to handle task completion and progress updates.\n- Progress tracking with individual task shares for better granularity.\n\n## Installation\n\nThis class is part of a Python project and requires Python 3.7 or later. Ensure you have `pydantic` installed:\n\n```bash\npip install simple-coroutine\n```\n\n```python\nimport asyncio\nfrom simple_coroutine.manager import CoroutineSession\n\nasync def sample_task(task_id):\n await asyncio.sleep(2) # Simulate a task taking some time\n return f\"Task {task_id} completed\"\n\nasync def main():\n session = CoroutineSession(\n max_concurrent_tasks=2,\n batch_delay=5,\n callback=lambda index, result: print(f\"Task {index} result: {result}\"),\n progress_callback=lambda index, progress, total: print(f\"Task {index} progress: {progress}, Total: {total}\")\n )\n\n tasks = [sample_task(i) for i in range(5)]\n session.add_task_set(tasks)\n \n results = await session.run_tasks()\n print(\"All tasks completed:\", results)\n\n async for progress in session.progress_generator():\n print(f\"Progress: {progress}%\")\n\nif __name__ == \"__main__\":\n asyncio.run(main())\n```",
"bugtrack_url": null,
"license": null,
"summary": "A simplified interface for managing coroutines with callback entry to monitor progress",
"version": "0.1.5",
"project_urls": {
"Homepage": "https://github.com/hragbalian/coroutine_manager",
"Repository": "https://github.com/hragbalian/coroutine_manager"
},
"split_keywords": [
"coroutines",
" async",
" asyncio",
" callback"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "99c85ded03a33641186ef05febedac1e24c3c6457bd59c2b9ba2a3c1108910a6",
"md5": "df3d3ddba20085e88f6c62f864710497",
"sha256": "0979e2958121b0b44a7f87bedb385dbb029472af35ae8e761598d64c42400ef7"
},
"downloads": -1,
"filename": "simple_coroutine-0.1.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "df3d3ddba20085e88f6c62f864710497",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.11",
"size": 3526,
"upload_time": "2024-07-13T23:36:16",
"upload_time_iso_8601": "2024-07-13T23:36:16.544300Z",
"url": "https://files.pythonhosted.org/packages/99/c8/5ded03a33641186ef05febedac1e24c3c6457bd59c2b9ba2a3c1108910a6/simple_coroutine-0.1.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "61e107493f6706400d7beff8648378b8b324ee44f6b1deeb4fb15438eff16208",
"md5": "f4f34837863f915918731d9e68222c01",
"sha256": "1cf90d4abcdb53200cc022d459537cb3c6e9f59f463db157b36a39cf05610e0d"
},
"downloads": -1,
"filename": "simple_coroutine-0.1.5.tar.gz",
"has_sig": false,
"md5_digest": "f4f34837863f915918731d9e68222c01",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.11",
"size": 2846,
"upload_time": "2024-07-13T23:36:17",
"upload_time_iso_8601": "2024-07-13T23:36:17.831760Z",
"url": "https://files.pythonhosted.org/packages/61/e1/07493f6706400d7beff8648378b8b324ee44f6b1deeb4fb15438eff16208/simple_coroutine-0.1.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-13 23:36:17",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "hragbalian",
"github_project": "coroutine_manager",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "simple-coroutine"
}