Collection of utilies for working with asynchronous Python code
Project description
aiodrive
aiodrive is a Python package for working with asynchronous code powered by asyncio. It only works on 3.12 and later.
Installation
$ pip install aiodrive
Pools
A pool is a collection of tasks that run at the same time. If any task fails, all other tasks are cancelled and all errors are raised, using an ExceptionGroup if necessary. If the parent task is cancelled, all tasks in the pool are cancelled as well.
The easiest way to create a pool is to use the Pool.open() asynchronous context manager.
from aiodrive import Pool
async def job1():
...
async def job2():
...
async with Pool.open() as pool:
pool.spawn(job1())
pool.spawn(job2())
An alternative is to use the Pool() constructor and the Pool.run() method.
pool = Pool()
pool.spawn(job1())
pool.spawn(job2())
await pool.run()
# Or if there is no event loop running
asyncio.run(pool.run())
Latch events
A latch event is an object similar to asyncio.Event that can be watched for both its set and unset states.
online_event = LatchEvent()
async def loop():
while True:
await online_event.wait_set()
print('Now online')
await online_event.wait_unset()
print('Now offline')
# Somewhere else
online_event.set()
online_event.unset()
Utility functions
aexit_handler()– Decorate an asynchronous context manager's__aexit__()method for it to collect both exceptions raised inside the method and by the context manager's consumer.cancel_task()– Cancel a task and await it.prime()– Immediately execute as much as code as possible of a coroutine before it is awaited.race()– Run multiple tasks and return the result of the first one to finish, after having cancelled and awaited the other tasks.shield()– Shield a task against cancellation and await it, unlikeasyncio.shield().timeout()– Run a block of code with a timeout, unlikeasyncio.wait_for()which only supports a single awaitable.try_all()– Run multiple tasks and cancel those still running if one of them raises an exception.wait_all()– Run multiple tasks without cancelling any if one raises an exception.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
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 aiodrive-1.0-py3-none-any.whl.
File metadata
- Download URL: aiodrive-1.0-py3-none-any.whl
- Upload date:
- Size: 37.2 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 |
5666e536218747534d39fa56545103f76e555809370b997d312132a6641e0d29
|
|
| MD5 |
50aa9ab68b3e173c05e30767925d59c7
|
|
| BLAKE2b-256 |
ece7dc9c7b1a918d6a953dcf5223380228916044c364daf435a1f124628382e7
|
Provenance
The following attestation bundles were made for aiodrive-1.0-py3-none-any.whl:
Publisher:
publish.yml on slietar/aiodrive
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aiodrive-1.0-py3-none-any.whl -
Subject digest:
5666e536218747534d39fa56545103f76e555809370b997d312132a6641e0d29 - Sigstore transparency entry: 310720638
- Sigstore integration time:
-
Permalink:
slietar/aiodrive@5dcf0b4ec9297ce62374a7870ae3ece14c30a863 -
Branch / Tag:
refs/tags/1.0 - Owner: https://github.com/slietar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5dcf0b4ec9297ce62374a7870ae3ece14c30a863 -
Trigger Event:
push
-
Statement type: