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 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

simple_coroutine-0.1.3.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.3-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: simple_coroutine-0.1.3.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.3.tar.gz
Algorithm Hash digest
SHA256 7bd761533ce30fc367d6e6a67afef613c8d286cd15b1d2d9c901966b74e53730
MD5 110fb0c34a2a1f5ac3ba21440298d0e4
BLAKE2b-256 15f9263f98c3abd1ed65e634541b0eb9e1fbed8af5a3296c6433c76d3e353351

See more details on using hashes here.

File details

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

File metadata

  • Download URL: simple_coroutine-0.1.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d2cdc9636f52359dab7a185fb6d2673aebc275282f2fa79bf9680a11515295f5
MD5 6325b95021f0dd23848528a904c4797a
BLAKE2b-256 78bfdd9fa0e274f5fc006438ef59f3c55bd1f1f16d52ccac3ca1134b5f2701f9

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