aiotimeout

Timeout context manager for asyncio Python
Usage
from aiotimeout import timeout
# Will raise an asyncio.TimeoutError
with timeout(1):
await asyncio.sleep(1.5)
# Will not raise anything
with timeout(1):
await asyncio.sleep(0.5)
You can respond to a timeout from outside the context by catching asyncio.TimeoutError
try:
with timeout(1):
await asyncio.sleep(1.5)
print('This line is not reached')
except asyncio.TimeoutError:
print('Timed out')
or you can respond to a timeout from inside the context by catching asyncio.CancelledError and re-raising.
try:
with timeout(1):
try:
await asyncio.sleep(1.5)
except asyncio.CancelledError
print('Doing some cleanup')
raise
except asyncio.TimeoutError:
print('Timed out')
Differences to alternatives
-
asyncio.wait_fordoes not offer a context manager. In some cases a context manager is clearer. -
asyncio.wait_forcreates/uses an extra task. In some cases this is not necessary, and an extra task adds non-determinism in terms of sequence of operations. -
Clearer internal code [in the author's opinion]. Rather than a custom class, contextlib.contextmanager is used.
Metadata
Release files for aiotimeout 0.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| aiotimeout-0.0.4.tar.gz | 2.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| aiotimeout-0.0.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 5.1 kB
Release files / aiotimeout-0.0.4.tar.gz
| Download URL | aiotimeout-0.0.4.tar.gz |
|---|---|
| Size | 2.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f237259423f3dac001f5cf4f75c7637ba914b623186eefd49b6a3d3b47bba0b9
|
|
BLAKE2b-256 checksum How to use checksums |
909f822949c457bc1bd54694a241b72e11096399e3d75bc75413e8acd23b636d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.7.1 requests-toolbelt/0.8.0 tqdm/4.31.1 CPython/3.6.7
|
Release files / aiotimeout-0.0.4-py3-none-any.whl
| Download URL | aiotimeout-0.0.4-py3-none-any.whl |
|---|---|
| Size | 3.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
729eb5056bd424d5018429f7e338b195c2153348271a50ebaea6d95ec9c67185
|
|
BLAKE2b-256 checksum How to use checksums |
8377102afcae8950b728e18141efc5b14ada3873f535eeedc4657ad93159ccbe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.7.1 requests-toolbelt/0.8.0 tqdm/4.31.1 CPython/3.6.7
|