X Tutup
Skip to content

gh-145107: simplify staggered race using eager_start=False#145108

Open
graingert wants to merge 5 commits intopython:mainfrom
graingert:145107-simplify-happy-eyeballs
Open

gh-145107: simplify staggered race using eager_start=False#145108
graingert wants to merge 5 commits intopython:mainfrom
graingert:145107-simplify-happy-eyeballs

Conversation

@graingert
Copy link
Contributor

@graingert graingert commented Feb 22, 2026

@graingert graingert marked this pull request as ready for review February 22, 2026 11:39
@caje731
Copy link
Contributor

caje731 commented Feb 23, 2026

LGTM!

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR simplifies asyncio.staggered.staggered_race() by removing the internal “ok_to_start” synchronization mechanism and instead creating tasks with eager_start=False to avoid eager-execution ordering issues (gh-145107).

Changes:

  • Remove the ok_to_start/next_ok_to_start Event gating from the internal run_one_coro() chain.
  • Create staggered-race tasks with loop.create_task(..., eager_start=False) to prevent eager execution.
  • Add a Misc/NEWS.d entry documenting the change.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
Lib/asyncio/staggered.py Reworks task creation in staggered_race() to use eager_start=False and drops the extra coordination events.
Misc/NEWS.d/next/Library/2026-02-22-11-27-57.gh-issue-145107.ZlQXEZ.rst Adds a release-note fragment for the staggered_race change.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -0,0 +1 @@
simplify asyncio's ``staggered_race`` using ``eager_start=False``
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NEWS entry formatting doesn’t match the usual Misc/NEWS.d fragments (leading space, starts with lowercase, and lacks a period). Please rephrase to a full sentence starting with a capital letter and ending with a period (and keep consistent module naming, e.g. “asyncio.staggered_race”).

Suggested change
simplify asyncio's ``staggered_race`` using ``eager_start=False``
Simplify ``asyncio.staggered_race`` by using ``eager_start=False``.

Copilot uses AI. Check for mistakes.
futures.future_add_to_awaited_by(first_task, parent_task)
running_tasks.add(first_task)
first_task.add_done_callback(task_done)
# first_task has been appended to running_tasks so first_task is ok to start.
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment still refers to the removed “ok_to_start” gating (“ok to start”), which is now misleading after switching to eager_start=False. Please update or remove it to reflect the new start semantics.

Suggested change
# first_task has been appended to running_tasks so first_task is ok to start.
# first_task has been appended to running_tasks before the event loop starts running it.

Copilot uses AI. Check for mistakes.
Comment on lines +109 to +112
next_task = loop.create_task(
run_one_coro(this_failed),
eager_start=False,
)
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By forcing eager_start=False here, staggered_race will no longer exercise the eager-start path even when an eager task factory is installed; existing regression tests named “with eager tasks” may become less meaningful. Consider adding/adjusting a test that asserts staggered_race passes eager_start=False (e.g., via a task factory that records the eager_start kwarg) so this behavior can’t regress silently.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

X Tutup