summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-01-15 15:29:10 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2015-01-15 15:29:10 (GMT)
commit922bc2ca123630aa9cff63c605a82af05408318d (patch)
tree98bdd9abdbeabc074bd223e598f52eb9f0c4844f /Lib/asyncio
parentab8848bc2a64930e0e9a2e56592bb692fb31d9e9 (diff)
downloadcpython-922bc2ca123630aa9cff63c605a82af05408318d.zip
cpython-922bc2ca123630aa9cff63c605a82af05408318d.tar.gz
cpython-922bc2ca123630aa9cff63c605a82af05408318d.tar.bz2
Closes #23219: cancelling asyncio.wait_for() now cancels the task
Diffstat (limited to 'Lib/asyncio')
-rw-r--r--Lib/asyncio/tasks.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py
index 7959a55..63412a9 100644
--- a/Lib/asyncio/tasks.py
+++ b/Lib/asyncio/tasks.py
@@ -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()