Skip to main content

基于 asyncio 的异步任务运行器

Project description

asyncrunner

English | 中文

asyncrunner is an asyncio-based asynchronous task runner designed to help you easily implement concurrent task management. It supports task timeout control, concurrency limits, and callback functions after task completion, meeting most asynchronous task scheduling needs.

Installation

You can install the package via pip:

pip install async-task-runner

Or build and install using Poetry:

# Build package (in project root directory)
poetry build

# Install the generated package (assuming the generated file is async-task-runner-1.0.0-py3-none-any.whl)
pip install dist/async-task-runner-1.0.0-py3-none-any.whl

Features

  • High-performance Async Scheduling: Implemented based on asyncio, fully utilizing Python's asynchronous features
  • Concurrency Control: Uses asyncio.Semaphore to control the number of simultaneously running tasks
  • Task Timeout Control: Uses asyncio.wait_for to set timeout for each task
  • Task Callbacks: Supports triggering callback functions after task completion
  • Flexible Task Scheduling Interface:
    • run_tasks: Schedule tasks through a list of task dictionaries, each task dictionary should contain target (task coroutine function) and other parameters
    • run_tasks_by_list: Schedule tasks through parameter lists, suitable for cases where parameters are provided in list/tuple or dictionary form

Usage

import asyncio
from asyncrunner import AsyncRunner

async def example_task(x):
    await asyncio.sleep(1)
    return x * 2

async def main():
    # Create runner instance
    runner = AsyncRunner(max_workers=3)  # Limit concurrent tasks to 3
    
    # Prepare tasks
    tasks = [
        {"target": example_task, "args": (i,)} for i in range(5)
    ]
    
    # Run tasks and get results
    results = await runner.run_tasks(tasks)
    print(results)  # [0, 2, 4, 6, 8]

if __name__ == "__main__":
    asyncio.run(main())

License

This project is licensed under the MIT License.

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

async_task_runner-1.0.0.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

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

async_task_runner-1.0.0-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file async_task_runner-1.0.0.tar.gz.

File metadata

  • Download URL: async_task_runner-1.0.0.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for async_task_runner-1.0.0.tar.gz
Algorithm Hash digest
SHA256 2a2617afd48f6de616e8d38889ad0c890ecf897f10ee87820c27fdf16e599111
MD5 f8d4c0d491765baf8d4904781868181a
BLAKE2b-256 79d43c21c9bf5c83dfa8bec44b6328a73cbf6462eff1a039bdf777c52376547e

See more details on using hashes here.

Provenance

The following attestation bundles were made for async_task_runner-1.0.0.tar.gz:

Publisher: python-publish.yml on 869413421/asyncrunner

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file async_task_runner-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for async_task_runner-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2214316c251c70ca4ca5db1d55e141435cc9b0244227f8f3a90112154206cd39
MD5 23a88389ca753391072e5a1441c1037d
BLAKE2b-256 ab7cd123a59f6a401e79390c73a73cb776541073bdbdf2ca59e6de8aecf016ec

See more details on using hashes here.

Provenance

The following attestation bundles were made for async_task_runner-1.0.0-py3-none-any.whl:

Publisher: python-publish.yml on 869413421/asyncrunner

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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