Skip to main content

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, unlike asyncio.shield().
  • timeout() – Run a block of code with a timeout, unlike asyncio.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

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

aiodrive-1.0-py3-none-any.whl (37.2 kB view details)

Uploaded Python 3

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

Hashes for aiodrive-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5666e536218747534d39fa56545103f76e555809370b997d312132a6641e0d29
MD5 50aa9ab68b3e173c05e30767925d59c7
BLAKE2b-256 ece7dc9c7b1a918d6a953dcf5223380228916044c364daf435a1f124628382e7

See more details on using hashes here.

Provenance

The following attestation bundles were made for aiodrive-1.0-py3-none-any.whl:

Publisher: publish.yml on slietar/aiodrive

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