MCPcopy Index your code
hub / github.com/python/cpython / timeout

Function timeout

Lib/asyncio/timeouts.py:143–160  ·  view source on GitHub ↗

Timeout async context manager. Useful in cases when you want to apply timeout logic around block of code or in cases when asyncio.wait_for is not suitable. For example: >>> async with asyncio.timeout(10): # 10 seconds timeout ... await long_running_task() delay - value i

(delay: float | None)

Source from the content-addressed store, hash-verified

141
142
143def timeout(delay: float | None) -> Timeout:
144 """Timeout async context manager.
145
146 Useful in cases when you want to apply timeout logic around block
147 of code or in cases when asyncio.wait_for is not suitable. For example:
148
149 >>> async with asyncio.timeout(10): # 10 seconds timeout
150 ... await long_running_task()
151
152
153 delay - value in seconds or None to disable timeout logic
154
155 long_running_task() is interrupted by raising asyncio.CancelledError,
156 the top-most affected timeout() context manager converts CancelledError
157 into TimeoutError.
158 """
159 loop = events.get_running_loop()
160 return Timeout(loop.time() + delay if delay is not None else None)
161
162
163def timeout_at(when: float | None) -> Timeout:

Callers

nothing calls this directly

Calls 2

TimeoutClass · 0.85
timeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…