Skip to main content

Async-related stuff you miss in standard library

https://upload.wikimedia.org/wikipedia/commons/thumb/f/fe/The_Hanging_by_Jacques_Callot.jpg/500px-The_Hanging_by_Jacques_Callot.jpg

“The horrors of hanging tasks when using asyncio” by Jacques Callot

Safely run coroutines concurrently

The asyncio.gather() function has an issue: in case of error in one of coroutines the rest coroutines are left running detached. This might cause hard to detect problems. On the contrary, the async_plus.try_gather() insures all tasks are cancelled on error:

result1, result2 = await async_plus.try_gather(
    coroutine_func1(...),
    coroutine_func2(...),
)

Fire-and-forget task

With create_task() it’s your responsibility to retrieve exception. Usually this causes that exception is not seen until process finishes or even is not seen at all if process is killed. With launch_watched() exception is logged immediately when it’s raised.

async_plus.launch_watched(your_coroutine_func(...))

Structuring groups of tasks

async with async_plus.task_scope() as scope:
    scope.launch(coroutine_func1(...))
    scope.launch(coroutine_func2(...))
    await scope.wait()

By default, wait() call returns when all tasks finish or first exception occurs. In all cases all unfinished tasks are cancelled at the end of async with block.

Increase delay between attempts in supervisor

retry_delayer = async_plus.RetryDelayer([0, 10, 60], random_shift=1)
while True:
    try:
        await run_service_x()
    # In Python <3.8 it inherits from Exception
    except asyncio.CancelledError:
        raise
    except Exception:
        logger.exception('Error in service X:')
        await retry_delayer.sleep()

Log long waits

Does your program hang and you don’t know what it’s waiting for? Wrap suspicious coroutines with impatient() to see bottlenecks:

await async_plus.impatient(asyncio.sleep(10), log_after=5)

Or just log the time it took:

await async_plus.impatient(asyncio.sleep(10), log_completion='always')

Change log

See CHANGELOG.

Metadata

Release files for async-plus 0.3.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 async-plus 0.3.0
File Size Uploaded Provenance Actions
async_plus-0.3.0.tar.gz 9.8 kB Without provenance Details for async_plus-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for async-plus 0.3.0
File Interpreter ABI Platform Actions
async_plus-0.3.0-py3-none-any.whl Python 3 none any Details for async_plus-0.3.0-py3-none-any.whl

Total release size: 16.7 kB

Release files / async_plus-0.3.0.tar.gz

Download URL async_plus-0.3.0.tar.gz
Size 9.8 kB
Tags Source
SHA-256 checksum
How to use checksums
5910ac38609f2f0aaa0f668360f35aecf6849875e7064e3baa63e7d4e3a5b9c4
BLAKE2b-256 checksum
How to use checksums
a67963cdc4ee0d87b7637f9a45b1b7454518a51e5c53879e850ee874d25813ef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.8.5

Release files / async_plus-0.3.0-py3-none-any.whl

Download URL async_plus-0.3.0-py3-none-any.whl
Size 6.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
004938d3d922a7fe2dc9db95486b103b9ef2b64f5e887d8d9a60608a279dea40
BLAKE2b-256 checksum
How to use checksums
60818178c07df8869a4ac3cd66b946f540f18ca36c92108b9076a793af68361e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.8.5

Security for async-plus 0.3.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