summaryrefslogtreecommitdiff
path: root/Lib/asyncio
diff options
context:
space:
mode:
authorElvis Pranskevichus <elvis@magic.io>2020-08-26 09:42:45 -0700
committerGitHub <noreply@github.com>2020-08-26 09:42:45 -0700
commita2118a14627256197bddcf4fcecad4c264c1e39d (patch)
tree038b42295921bd86908f322143586e4d083d7cfd /Lib/asyncio
parentc517fc712105c8e5930cb42baaebdbe37fc3e15f (diff)
downloadcpython-git-a2118a14627256197bddcf4fcecad4c264c1e39d.tar.gz
bpo-37658: Fix asyncio.wait_for() to respect waited task status (#21894)
Currently, if `asyncio.wait_for()` itself is cancelled it will always raise `CancelledError` regardless if the underlying task is still running. This is similar to a race with the timeout, which is handled already.
Diffstat (limited to 'Lib/asyncio')
-rw-r--r--Lib/asyncio/tasks.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py
index 7ecec96384..8b05434f27 100644
--- a/Lib/asyncio/tasks.py
+++ b/Lib/asyncio/tasks.py
@@ -465,9 +465,12 @@ async def wait_for(fut, timeout, *, loop=None):
try:
await waiter
except exceptions.CancelledError:
- fut.remove_done_callback(cb)
- fut.cancel()
- raise
+ if fut.done():
+ return fut.result()
+ else:
+ fut.remove_done_callback(cb)
+ fut.cancel()
+ raise
if fut.done():
return fut.result()