summaryrefslogtreecommitdiff
path: root/asyncio
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-01-15 16:25:54 +0100
committerVictor Stinner <victor.stinner@gmail.com>2015-01-15 16:25:54 +0100
commitd0b9679f9198df2bfef2e9faaed70d68f9067271 (patch)
treeb3610ec747bf0c4615453b6675690535ced9fee8 /asyncio
parente70e384fcebeb63a4fc0e690e47b4d24437a5c95 (diff)
downloadtrollius-d0b9679f9198df2bfef2e9faaed70d68f9067271.tar.gz
Python issue #23219: cancelling wait_for() now cancels the task
Diffstat (limited to 'asyncio')
-rw-r--r--asyncio/tasks.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/asyncio/tasks.py b/asyncio/tasks.py
index 7959a55..63412a9 100644
--- a/asyncio/tasks.py
+++ b/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()