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.2.1 (2017-05-02)

  • Support unpublished event loop’s “current_task” api.

1.2.0 (2017-03-11)

  • Extra check on context manager exit

  • 0 is no-op timeout

1.1.0 (2016-10-20)

  • Rename to async-timeout

1.0.0 (2016-09-09)

  • 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.2.1.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

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

async_timeout-1.2.1-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file async-timeout-1.2.1.tar.gz.

File metadata

  • Download URL: async-timeout-1.2.1.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for async-timeout-1.2.1.tar.gz
Algorithm Hash digest
SHA256 380e9bfd4c009a14931ffe487499b0906b00b3378bb743542cfd9fbb6d8e4657
MD5 e71f9b197498f917864e29af7a5defa0
BLAKE2b-256 eba39fbe8bf7de4128d8f5562ca0b7b2f81d21b006085149528b937e1624e71f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for async_timeout-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fe2f598eb140a444cc4ba15010f109259ad8eebcb11a9107fdb9ea32139bc722
MD5 7f08e713d9ecc347a8f0931d213a7c75
BLAKE2b-256 460844b31f56d9c86ffc8c0abb320fe8465a1a5ae59dc2baddee383b4b3dd813

See more details on using hashes here.

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