Registry / http-networking / async-timeout

async-timeout

JSON →
library5.0.1pypypi✓ verified 52d ago

Provides a timeout context manager for asyncio programs, allowing for easy management of timeouts in asynchronous code. Current version: 5.0.1. Maintained with regular updates.

http-networkingweb-framework
pip install async-timeout
Install & Compatibility
Where this runs
tested against v5.0.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.925 runs
installs and imports cleanly · install 0.0s · import 0.212s · 17.8MB
glibc
py 3.103.925 runs
installs and imports cleanly · install 1.6s · import 0.182s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Timeout
from async_timeout import timeout
Ensure correct import path to avoid ImportError

Demonstrates usage of the timeout context manager to set a 10-second timeout for an asynchronous operation.

import asyncio from async_timeout import timeout async def main(): async with timeout(10): await asyncio.sleep(5) print('Completed within timeout') asyncio.run(main())
Debug
Known issues
breakingVersion 5.0.0 introduced changes to the 'timeout' function, making it fully compatible with the standard 'asyncio.Timeout'.
fix
Update your code to use the new 'timeout' function signature and behavior.
affects: 5.0.0
deprecatedSupport for Python 3.6 was dropped in version 4.0.3.
fix
Upgrade your Python environment to version 3.7 or higher.
affects: 4.0.3
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'async_timeout'
The 'async_timeout' module is not installed in the Python environment.
fix
Install the module using pip: 'pip install async-timeout'.
ImportError: cannot import name 'timeout' from 'async_timeout'
The 'timeout' function is not available in the 'async_timeout' module, possibly due to an outdated version.
fix
Ensure you have the latest version installed: 'pip install --upgrade async-timeout'.
AttributeError: module 'async_timeout' has no attribute 'timeout'
The 'timeout' attribute is missing from the 'async_timeout' module, likely due to an incorrect installation or version.
fix
Verify the installation and version: 'pip show async-timeout' and upgrade if necessary.
TypeError: timeout() got an unexpected keyword argument 'timeout'
This issue arises when calling the `timeout` context manager with a keyword argument named `timeout`, while the function expects the duration as a positional argument or a different keyword like `delay`.
fix
Pass the timeout duration as the first positional argument, for example: `async with timeout(5.0):` instead of `async with timeout(timeout=5.0):`.
asyncio.TimeoutError
The asynchronous operation wrapped by the `async_timeout.timeout` context manager did not complete within the specified time limit, causing a `asyncio.TimeoutError` to be raised.
fix
Handle the `asyncio.TimeoutError` exception using a `try...except` block, increase the `timeout` duration if the operation legitimately takes longer, or optimize the underlying asynchronous code to complete faster.
Upgrade
Version history
5.0.1latest on PyPI
Audit
Dependencies
asynciorequiredRequired for asynchronous programming in Python
Agent activity
17 hits · last 30 days
node
4
seranking-bot
3
ahrefsbot
2
bytedance
2
Amazon
1
amazonbot
1
Resources