mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Closes #23219: cancelling asyncio.wait_for() now cancels the task
This commit is contained in:
parent
ab8848bc2a
commit
922bc2ca12
2 changed files with 35 additions and 4 deletions
|
@ -347,10 +347,9 @@ def wait_for(fut, timeout, *, loop=None):
|
|||
it cancels the task and raises TimeoutError. To avoid the task
|
||||
cancellation, wrap it in shield().
|
||||
|
||||
Usage:
|
||||
|
||||
result = yield from asyncio.wait_for(fut, 10.0)
|
||||
If the wait is cancelled, the task is also cancelled.
|
||||
|
||||
This function is a coroutine.
|
||||
"""
|
||||
if loop is None:
|
||||
loop = events.get_event_loop()
|
||||
|
@ -367,7 +366,12 @@ def wait_for(fut, timeout, *, loop=None):
|
|||
|
||||
try:
|
||||
# wait until the future completes or the timeout
|
||||
yield from waiter
|
||||
try:
|
||||
yield from waiter
|
||||
except futures.CancelledError:
|
||||
fut.remove_done_callback(cb)
|
||||
fut.cancel()
|
||||
raise
|
||||
|
||||
if fut.done():
|
||||
return fut.result()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue