8000 GH-86296: Fix for asyncio.wait_for() swallowing cancellation, and add tests by twisteroidambassador · Pull Request #98607 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

GH-86296: Fix for asyncio.wait_for() swallowing cancellation, and add tests #98607

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Prev Previous commit
Next Next commit
Ensure wait_for() does not swallow cancellation.
  • Loading branch information
twisteroidambassador committed Oct 25, 2022
commit 55f5547c704651423739449afb6ff8527d33b5d4
11 changes: 6 additions & 5 deletions Lib/asyncio/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,15 +468,16 @@ async def wait_for(fut, timeout):
try:
await waiter
except exceptions.CancelledError:
if fut.done():
return fut.result()
else:
fut.remove_done_callback(cb)
if not fut.done():
# We must ensure that the task is not running
# after wait_for() returns.
# See https://bugs.python.org/issue32751
fut.remove_done_callback(cb)
await _cancel_and_wait(fut, loop=loop)
raise
exc = fut.exception()
if exc: # If fut.cancelled(), this will raise CancelledError
raise exc
raise

if fut.done():
return fut.result()
Expand Down
0