diff options
author | Elvis Pranskevichus <elvis@magic.io> | 2020-08-26 16:42:45 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-26 16:42:45 (GMT) |
commit | a2118a14627256197bddcf4fcecad4c264c1e39d (patch) | |
tree | 038b42295921bd86908f322143586e4d083d7cfd /Lib/asyncio | |
parent | c517fc712105c8e5930cb42baaebdbe37fc3e15f (diff) | |
download | cpython-a2118a14627256197bddcf4fcecad4c264c1e39d.zip cpython-a2118a14627256197bddcf4fcecad4c264c1e39d.tar.gz cpython-a2118a14627256197bddcf4fcecad4c264c1e39d.tar.bz2 |
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.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py index 7ecec96..8b05434 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() |