An asyncio-based asynchronous task runner, ready to use out of the box.
Project description
asyncrunner
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.Semaphoreto control the number of simultaneously running tasks - Task Timeout Control: Uses
asyncio.wait_forto 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 containtarget(task coroutine function) and other parametersrun_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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file async_task_runner-1.0.3.tar.gz.
File metadata
- Download URL: async_task_runner-1.0.3.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ab995709daa71da027e2fadd6887aace65448d667bc9debed219461bb61ed889
|
|
| MD5 |
f109543ba2417fca780ab7b349773cd4
|
|
| BLAKE2b-256 |
464a2473530c62167a12e38c18fc54396d99ddcc7ab47a4d1a3f7ab61833e700
|
Provenance
The following attestation bundles were made for async_task_runner-1.0.3.tar.gz:
Publisher:
python-publish.yml on 869413421/asyncrunner
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
async_task_runner-1.0.3.tar.gz -
Subject digest:
ab995709daa71da027e2fadd6887aace65448d667bc9debed219461bb61ed889 - Sigstore transparency entry: 176662585
- Sigstore integration time:
-
Permalink:
869413421/asyncrunner@f38b16358963a373dbff8455ef2fc245b22bdf5d -
Branch / Tag:
refs/tags/v1.0.3 - Owner: https://github.com/869413421
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@f38b16358963a373dbff8455ef2fc245b22bdf5d -
Trigger Event:
push
-
Statement type:
File details
Details for the file async_task_runner-1.0.3-py3-none-any.whl.
File metadata
- Download URL: async_task_runner-1.0.3-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
28e37e2c8d835e1e7806171700f09b3f742d4092a84047f2cd2cd8eadbf34e93
|
|
| MD5 |
3ce8bbc5e047b22eb3503eb23f3c7978
|
|
| BLAKE2b-256 |
83cb18a13140a3ab1c482128df365a76cecd26b7f2469e0a3d600565a3eac427
|
Provenance
The following attestation bundles were made for async_task_runner-1.0.3-py3-none-any.whl:
Publisher:
python-publish.yml on 869413421/asyncrunner
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
async_task_runner-1.0.3-py3-none-any.whl -
Subject digest:
28e37e2c8d835e1e7806171700f09b3f742d4092a84047f2cd2cd8eadbf34e93 - Sigstore transparency entry: 176662592
- Sigstore integration time:
-
Permalink:
869413421/asyncrunner@f38b16358963a373dbff8455ef2fc245b22bdf5d -
Branch / Tag:
refs/tags/v1.0.3 - Owner: https://github.com/869413421
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@f38b16358963a373dbff8455ef2fc245b22bdf5d -
Trigger Event:
push
-
Statement type: