mirror of
https://github.com/python/cpython.git
synced 2025-09-11 11:17:16 +00:00
asyncio: wait_for() now cancels the future on timeout. Patch written by Gustavo
Carneiro.
This commit is contained in:
parent
183e347796
commit
421e49b5c1
2 changed files with 18 additions and 17 deletions
|
@ -382,8 +382,9 @@ def wait_for(fut, timeout, *, loop=None):
|
|||
|
||||
Coroutine will be wrapped in Task.
|
||||
|
||||
Returns result of the Future or coroutine. Raises TimeoutError when
|
||||
timeout occurs.
|
||||
Returns result of the Future or coroutine. When a timeout occurs,
|
||||
it cancels the task and raises TimeoutError. To avoid the task
|
||||
cancellation, wrap it in shield().
|
||||
|
||||
Usage:
|
||||
|
||||
|
@ -405,6 +406,7 @@ def wait_for(fut, timeout, *, loop=None):
|
|||
return fut.result()
|
||||
else:
|
||||
fut.remove_done_callback(cb)
|
||||
fut.cancel()
|
||||
raise futures.TimeoutError()
|
||||
finally:
|
||||
timeout_handle.cancel()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue