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

Uploaded Python 3

File details

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

File metadata

  • Download URL: simple_coroutine-0.1.4.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.4.tar.gz
Algorithm Hash digest
SHA256 ae675b50ded86f1b632c2cd18b297a1fcb7a9324b72b2694805b40b06944fd27
MD5 4b463ad351f9d3628334b197a1e48fc2
BLAKE2b-256 e7d5d7142242bd8be03d0377cd8ac496488b1035eb5d078c973b5efb4b029832

See more details on using hashes here.

File details

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

File metadata

  • Download URL: simple_coroutine-0.1.4-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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 3019d6949c6ce01764ea1e0a28e83943c942148bf9ce6fdc9b8a9663f66b9ab9
MD5 036f1fbb14decaac6d01c24636bba45f
BLAKE2b-256 b2215707de9343d7515fcc1dee6bd463e8216588cfcc7c6b4297ccc32e7a4777

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