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.
This commit is contained in:
Elvis Pranskevichus 2020-08-26 09:42:45 -07:00 committed by GitHub
parent c517fc7121
commit a2118a1462
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 3 deletions

View file

@ -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()