A simplified interface for managing coroutines with callback entry to monitor progress
Project description
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:
pip install simple-coroutine
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())
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file simple_coroutine-0.1.5.tar.gz.
File metadata
- Download URL: simple_coroutine-0.1.5.tar.gz
- Upload date:
- Size: 2.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.11.9 Linux/6.5.0-1023-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1cf90d4abcdb53200cc022d459537cb3c6e9f59f463db157b36a39cf05610e0d
|
|
| MD5 |
f4f34837863f915918731d9e68222c01
|
|
| BLAKE2b-256 |
61e107493f6706400d7beff8648378b8b324ee44f6b1deeb4fb15438eff16208
|
File details
Details for the file simple_coroutine-0.1.5-py3-none-any.whl.
File metadata
- Download URL: simple_coroutine-0.1.5-py3-none-any.whl
- Upload date:
- Size: 3.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.11.9 Linux/6.5.0-1023-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0979e2958121b0b44a7f87bedb385dbb029472af35ae8e761598d64c42400ef7
|
|
| MD5 |
df3d3ddba20085e88f6c62f864710497
|
|
| BLAKE2b-256 |
99c85ded03a33641186ef05febedac1e24c3c6457bd59c2b9ba2a3c1108910a6
|