Skip to content
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

GH-124639: add back loop param to staggered_race #124700

Merged
merged 5 commits into from
Sep 29, 2024
Merged
Changes from 4 commits
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
10 changes: 8 additions & 2 deletions Lib/asyncio/staggered.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class _Done(Exception):
pass

async def staggered_race(coro_fns, delay):
async def staggered_race(coro_fns, delay, *, loop=None):
"""Run coroutines with staggered start times and take the first to finish.
This method takes an iterable of coroutine functions. The first one is
Expand Down Expand Up @@ -82,7 +82,13 @@ async def run_one_coro(this_index, coro_fn, this_failed):
raise _Done

try:
async with taskgroups.TaskGroup() as tg:
tg = taskgroups.TaskGroup()
# Intentionally override the loop in the TaskGroup to avoid
# using the running loop, preserving backwards compatibility
# TaskGroup only starts using `_loop` after `__aenter__`
# so overriding it here is safe.
tg._loop = loop
gvanrossum marked this conversation as resolved.
Show resolved Hide resolved
async with tg:
for this_index, coro_fn in enumerate(coro_fns):
this_failed = locks.Event()
exceptions.append(None)
Expand Down
Loading