GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-157157: Make test_taskgroup_cancel_keeps_outer_cancellation deterministic by iamsharduld · Pull Request #157158 · python/cpython

Conversation

@iamsharduld

@iamsharduld iamsharduld commented Sep 8, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Fixes the timing dependence described in the issue: the test cancelled the parent task from outside after await asyncio.sleep(0.01), and lost the cancellation message whenever the loop stalled for more than 10 ms before the body task first ran (the mechanism, and a reproducer that stalls the loop with time.sleep(), are in the issue).

The test now synchronizes on two events instead of sleeping. The child signals from its finally block that the group is cancelling, which by then has cancelled the parent task and is waiting for the child, and waits there until the test releases it. Only then does the test cancel the parent task from outside. The ordering is fixed by the callback queue, not by time, so it holds on any build speed and for both task implementations.

Checked:

  • The rewritten test passes for TestTaskGroup and TestEagerTaskTaskGroup, 10 of 10 repeated runs, and the whole test_asyncio.test_taskgroups module passes.
  • With the asyncio.TaskGroup swallows cancellations coming from outside of it #155433 fix reverted locally, the rewritten test still fails in both classes (CancelledError not raised), so it keeps guarding the bug it was written for.
  • The event-based ordering was also verified in a standalone harness with the same 20 ms loop stall that makes the current test fail.

Since the original test was added by the gh-155433 fix, this likely wants the same backports.

  • Issue: test_taskgroup_cancel_keeps_outer_cancellation is timing-dependent and fails on slow (TSan) CI #157157

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@iamsharduld
pythongh-157157: Make test_taskgroup_cancel_keeps_outer_cancellation …
86ee308
…deterministic

The test cancelled the parent task from outside after a 10 ms sleep,
expecting the group to still be waiting for its child. If the event loop
stalled for longer than that before the body task first ran, the outer
cancel() landed while the parent's awaited future was already cancelled
by the group, and its message was dropped, failing the test on slow
builds such as the TSan CI job.

Synchronize on events instead: the child signals from its finally block
that the group is cancelling and waits to be released, and only then is
the parent task cancelled from outside.
@iamsharduld
iamsharduld requested review from 1st1, asvetlov, kumaraditya303 and willingc as code owners September 8, 2026 04:17
@bedevere-app bedevere-app Bot mentioned this pull request Sep 8, 2026
test_taskgroup_cancel_keeps_outer_cancellation is timing-dependent and fails on slow (TSan) CI #157157
Closed
@bedevere-app bedevere-app Bot added tests Tests in the Lib/test dir awaiting review labels Sep 8, 2026
@iamsharduld iamsharduld mentioned this pull request Sep 8, 2026
gh-131178: Add tests for ensurepip command-line interface #157154
Open
kumaraditya303
kumaraditya303 reviewed Sep 8, 2026
View reviewed changes
Comment thread Misc/NEWS.d/next/Tests/2026-09-08-02-40-00.gh-issue-157157.5X2ypw.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@kumaraditya303 kumaraditya303 added the skip news label Sep 8, 2026
@iamsharduld
Remove the NEWS entry
c4778ee
@iamsharduld

iamsharduld commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

I have made the requested changes; please review again

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot added awaiting change review and removed awaiting review labels Sep 8, 2026
@bedevere-app

bedevere-app Bot commented Sep 8, 2026

Copy link
Copy Markdown

Thanks for making the requested changes!

: please review the changes made to this pull request.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This was referenced Sep 8, 2026
gh-157184: Scale the join() alarm in the multiprocessing kill tests #157185
Closed
gh-131178: Add tests for pstats command-line interface #157133
Open
gh-157161: Fix test_rollover_based_on_st_birthtime_only on slow machines #157162
Open
kumaraditya303
kumaraditya303 approved these changes Sep 11, 2026
View reviewed changes
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting change review labels Sep 11, 2026
@kumaraditya303
kumaraditya303 merged commit 1c641ff into python:main Sep 11, 2026
53 of 56 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting merge label Sep 11, 2026
clin1234 pushed a commit to clin1234/cpython that referenced this pull request Sep 12, 2026
@iamsharduld @clin1234
pythongh-157157: Make test_taskgroup_cancel_keeps_outer_cancellation …
e8cdbd2
…deterministic (python#157158)
johnslavik pushed a commit to johnslavik/cpython that referenced this pull request Sep 14, 2026
@iamsharduld @johnslavik
pythongh-157157: Make test_taskgroup_cancel_keeps_outer_cancellation …
079e137
…deterministic (python#157158)
@aisk aisk mentioned this pull request Oct 14, 2026
gh-159293: Restore the recursion limit after the free-threading race test #159311
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@kumaraditya303 kumaraditya303 kumaraditya303 approved these changes
@1st1 1st1 Awaiting requested review from 1st1 1st1 is a code owner
@asvetlov asvetlov Awaiting requested review from asvetlov asvetlov is a code owner
@willingc willingc Awaiting requested review from willingc willingc is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

skip news tests Tests in the Lib/test dir

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@iamsharduld @kumaraditya303
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.