summaryrefslogtreecommitdiff
path: root/Lib/asyncio
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2020-08-26 10:14:59 -0700
committerGitHub <noreply@github.com>2020-08-26 19:14:59 +0200
commit1036ccb55de4abc70837cb46a72ddbb370b8fc94 (patch)
tree307a6e80f9467c7ad18242c717c772d5e3fc809f /Lib/asyncio
parentd7cd1164c18dbf78380ce4c95bf46c7bb0ac0bb7 (diff)
downloadcpython-git-1036ccb55de4abc70837cb46a72ddbb370b8fc94.tar.gz
bpo-32751: Wait for task cancel in asyncio.wait_for() when timeout <= 0 (GH-21895) (GH-21963)
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. (cherry picked from commit c517fc712105c8e5930cb42baaebdbe37fc3e15f) Co-authored-by: Elvis Pranskevichus <elvis@magic.io>
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 c37f0e1387..7ecec96384 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)