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

Uploaded Python 3

File details

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

File metadata

  • Download URL: simple_coroutine-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 2f2feafd6f11eef6c7eadd3ab81ca9dfa03641c1481503142af08aa211f03fd5
MD5 aade27f1bf5bc0631c8d455689d04fc7
BLAKE2b-256 de3e278f219b7c35b93e249f70a998230cf0924cf10cbc65ab58391b77c08fa5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: simple_coroutine-0.1.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4c28260be84e6f6148a81638fad7b6312954ed4366af16f624322570d289c817
MD5 ba0c8d34f9ab126de74db3b183d23328
BLAKE2b-256 b1f010c35e94f6aeb6855ccf10e0776eca74b3b928771dadef3bd24351cd69f9

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