8000 Replace `wait_for` with `wait`. · python/cpython@513f7f9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 513f7f9

Browse files
Replace wait_for with wait.
This solution is compatible with all Python versions, and should pass all tests.
1 parent afb6abf commit 513f7f9

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

Lib/asyncio/staggered.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
__all__ = 'staggered_race',
44

5-
import contextlib
65
import typing
76

87
from . import events
9-
from . import exceptions as exceptions_mod
108
from . import locks
119
from . import tasks
1210

@@ -83,12 +81,11 @@ async def run_one_coro(
8381
previous_failed: typing.Optional[locks.Event]) -> None:
8482
# Wait for the previous task to finish, or for delay seconds
8583
if previous_failed is not None:
86-
with contextlib.suppress(exceptions_mod.TimeoutError):
87-
# Use asyncio.wait_for() instead of asyncio.wait() here, so
88-
# that if we get cancelled at this point, Event.wait() is also
89-
# cancelled, otherwise there will be a "Task destroyed but it is
90-
# pending" later.
91-
await tasks.wait_for(previous_failed.wait(), delay)
84+
wait_task = tasks.create_task(previous_failed.wait())
85+
try:
86+
await tasks. 53FF wait((wait_task,), timeout=delay)
87+
finally:
88+
wait_task.cancel()
9289
# Get the next coroutine to run
9390
try:
9491
this_index, coro_fn = next(enum_coro_fns)

0 commit comments

Comments
 (0)
0