Skip to main content

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 pydantic
import asyncio
from your_module import CoroutineSession  # replace with the actual import path

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

simple_coroutine-0.1.1.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

simple_coroutine-0.1.1-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file simple_coroutine-0.1.1.tar.gz.

File metadata

  • Download URL: simple_coroutine-0.1.1.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.9 Darwin/23.5.0

File hashes

Hashes for simple_coroutine-0.1.1.tar.gz
Algorithm Hash digest
SHA256 39cd18ba0b38e5695bcfb7783ab3388439cd280a618f2cc67f58327ebbbebed1
MD5 4834a457b95220a8b513e6074464e2ac
BLAKE2b-256 97d3e6547daf51554d8e1e6548aedb59b5636eb58b7c09fd9551ba3533cc9a23

See more details on using hashes here.

File details

Details for the file simple_coroutine-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: simple_coroutine-0.1.1-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 Darwin/23.5.0

File hashes

Hashes for simple_coroutine-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9d52b633bfb0a0859c39668dff40c1773808ae14315ab3c59a9c2f82cc07487d
MD5 fe653720ba2a37d32d3606f308da4579
BLAKE2b-256 908e341172c06244b6cefefacd63370a093d13911f7f12f3e0ad6ee570b958a8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page