Skip to main content

Timeout context manager for asyncio programs

Project description

async_timeout

asyncio-compatible timeout context manager.

Usage example

The context manager is useful in cases when you want to apply timeout logic around block of code or in cases when asyncio.wait_for() is not suitable. Also it’s much faster than asyncio.wait_for() because timeout doesn’t create a new task.

The timeout(timeout, *, loop=None) call returns a context manager that cancels a block on timeout expiring:

with timeout(1.5):
    yield from inner()
  1. If inner() is executed faster than in 1.5 seconds nothing happens.

  2. Otherwise inner() is cancelled internally by sending asyncio.CancelledError into but asyncio.TimeoutError is raised outside of context manager scope.

timeout parameter could be None for skipping timeout functionality.

Installation

$ pip install async_timeout

The library is Python 3 only!

Authors and License

The module is written by Andrew Svetlov.

It’s Apache 2 licensed and freely available.

CHANGES

1.0.0 (2016-09-XX)

  • The first release.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

async_timeout-1.0.0.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

async_timeout-1.0.0-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file async_timeout-1.0.0.tar.gz.

File metadata

File hashes

Hashes for async_timeout-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c7afd7355b93fca0aecc15811aa53eea57f6fd7307b5bff2336b01419ebeda36
MD5 f8baef770792f04fa3d74e7d083c43e9
BLAKE2b-256 c35bd00e06296f5fe2c1db230f5f3f39538a4ae23c153adb1672e87e94137f89

See more details on using hashes here.

Provenance

File details

Details for the file async_timeout-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for async_timeout-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6d3fd64572c13b75f9f1cbb7e7de089cc7ae119a26913573813a9124651df923
MD5 2dec8641f93ae9b6410927673c88068c
BLAKE2b-256 b4e65dc387267854666df7d2e5e5a305c8b2e037056bdf8bb278aed488670598

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page