8000 bpo-42130: Fix for explicit suppressing of cancellations in wait_for() by Dreamsorcerer · Pull Request #28149 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-42130: Fix for explicit suppressing of cancellations in wait_for() #28149

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
wants to merge 20 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use a sentinel
  • Loading branch information
Dreamsorcerer authored Sep 3, 2021
commit 01d988459f6020a5bd2df73946a358c07a93b74a
8 changes: 5 additions & 3 deletions Lib/asyncio/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
from . import futures
from .coroutines import _is_coroutine

_SENTINEL = object()

# Helper to generate new task names
# This uses itertools.count() instead of a "+= 1" operation because the latter
# is not thread safe. See bpo-11866 for a longer explanation.
Expand Down Expand Up @@ -432,8 +434,8 @@ async def wait_for(fut, timeout):
# wait until the future completes or the timeout
try:
await waiter
except exceptions.CancelledError:
if fut.done():
except exceptions.CancelledError as e:
if fut.done() and _SENTINEL in e.args:
return fut.result()
else:
fut.remove_done_callback(cb)
Expand Down Expand Up @@ -516,7 +518,7 @@ async def _cancel_and_wait(fut, loop):
fut.add_done_callback(cb)

try:
fut.cancel()
fut.cancel(_SENTINEL)
# We cannot wait on *fut* directly to make
# sure _cancel_and_wait itself is reliably cancellable.
await waiter
Expand Down
0