Skip to main content

asyncio_tools

Useful utilities for working with asyncio.

gather

Provides a convenient wrapper around asyncio.gather.

from asyncio_tools import gather, CompoundException


async def good():
    return 'OK'


async def bad():
    raise ValueError()


async def main():
    response = await gather(
        good(),
        bad(),
        good()
    )

    # Check if a particular exception was raised.
    ValueError in response.exception_types
    # >>> True

    # To get all exceptions:
    print(response.exceptions)
    # >>> [ValueError()]

    # To get all instances of a particular exception:
    response.exceptions_of_type(ValueError)
    # >>> [ValueError()]

    # To get the number of exceptions:
    print(response.exception_count)
    # >>> 1

    # You can still access all of the results:
    print(response.all)
    # >>> ['OK', ValueError(), 'OK']

    # And can access all successes (i.e. non-exceptions):
    print(response.successes)
    # >>> ['OK', 'OK']

    # To get the number of successes:
    print(response.success_count)
    # >>> 2

    try:
        # To combines all of the exceptions into a single one, which merges the
        # messages.
        raise response.compound_exception()
    except CompoundException as compound_exception:
        print("Caught it")

        if ValueError in compound_exception.exception_types:
            print("Caught a ValueError")

Read some background on why gather is useful:

Metadata

Release files for asyncio-tools 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for asyncio-tools 1.0.0
File Size Uploaded Provenance
asyncio_tools-1.0.0.tar.gz 3.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for asyncio-tools 1.0.0
File Interpreter ABI Platform
asyncio_tools-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 7.7 kB

Release files / asyncio_tools-1.0.0.tar.gz

Download URL asyncio_tools-1.0.0.tar.gz
Size 3.7 kB
Tags Source
SHA-256 checksum
How to use checksums
21bde808c149c74b3178d407ac31cf2bad00e7fad33d12230115e9874763133e
BLAKE2b-256 checksum
How to use checksums
9680dd6ace29eb652273439fa50f8dba4d8900f4f36ab99cf2a29b6fa7bf1857
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.7

Release files / asyncio_tools-1.0.0-py3-none-any.whl

Download URL asyncio_tools-1.0.0-py3-none-any.whl
Size 4.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
54f5033699df063b393d99bb744895cf9fad28062ff83717f9b2f54344f89c97
BLAKE2b-256 checksum
How to use checksums
167cb0fde3dc52ce369a485767472d9b17301714522976b1f82efaf43ff5d49a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.7

Security for asyncio-tools 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page