summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio
diff options
context:
space:
mode:
authorElvis Pranskevichus <elvis@magic.io>2020-08-26 16:42:22 (GMT)
committerGitHub <noreply@github.com>2020-08-26 16:42:22 (GMT)
commitc517fc712105c8e5930cb42baaebdbe37fc3e15f (patch)
tree4d9dc30f313e5be53ec5dd9d2cfa80ca4e7f900d /Lib/asyncio
parent8e19c8be87017f6bef8e4c936b1e6ddacb558ad2 (diff)
downloadcpython-c517fc712105c8e5930cb42baaebdbe37fc3e15f.zip
cpython-c517fc712105c8e5930cb42baaebdbe37fc3e15f.tar.gz
cpython-c517fc712105c8e5930cb42baaebdbe37fc3e15f.tar.bz2
bpo-32751: Wait for task cancel in asyncio.wait_for() when timeout <= 0 (#21895)
When I was fixing bpo-32751 back in GH-7216 I missed the case when *timeout* is zero or negative. This takes care of that. Props to @aaliddell for noticing the inconsistency.
Diffstat (limited to 'Lib/asyncio')
-rw-r--r--Lib/asyncio/tasks.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py
index c37f0e1..7ecec96 100644
--- a/Lib/asyncio/tasks.py
+++ b/Lib/asyncio/tasks.py
@@ -445,8 +445,13 @@ async def wait_for(fut, timeout, *, loop=None):
if fut.done():
return fut.result()
- fut.cancel()
- raise exceptions.TimeoutError()
+ await _cancel_and_wait(fut, loop=loop)
+ try:
+ fut.result()
+ except exceptions.CancelledError as exc:
+ raise exceptions.TimeoutError() from exc
+ else:
+ raise exceptions.TimeoutError()
waiter = loop.create_future()
timeout_handle = loop.call_later(timeout, _release_waiter, waiter)