Skip to content

gh-160986: Sample popped frames only after leaf() is running - #160990

Closed
timurzvural wants to merge 2 commits into
python:mainfrom
timurzvural:fix/160986-popping-frame-sample-race
Closed

timurzvural wants to merge 2 commits into
python:mainfrom
timurzvural:fix/160986-popping-frame-sample-race

Conversation

@timurzvural

@timurzvural timurzvural commented Oct 30, 2026 •

Copy link
Copy Markdown

Fixes #160986.

test_popping_python_frame_is_not_native created RemoteUnwinder as soon as the child process could be read, then took a fixed 10,000 samples. On a slow startup those samples all landed during interpreter startup, before leaf() existed, so the test observed zero frames and failed. It now waits until leaf is on the stack, then takes the sample window. The check that a popping leaf frame is never reported as <native> is unchanged.

Per review feedback, this PR only changes the test (no NEWS entry).

This pull request was prepared with Cursor Agent.

@python-cla-bot

python-cla-bot Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app bedevere-app Bot added the tests Tests in the Lib/test dir label Oct 30, 2026
@timurzvural
timurzvural force-pushed the fix/160986-popping-frame-sample-race branch from 38c1ea6 to ba60c58 Compare October 30, 2026 22:29
test_popping_python_frame_is_not_native attached as soon as the child
process could be read, then took a fixed 10,000 samples. On a slow
startup those samples all landed before leaf(), so the test observed
zero frames.
@timurzvural
timurzvural force-pushed the fix/160986-popping-frame-sample-race branch from ba60c58 to 77f83ef Compare October 30, 2026 22:30
@NekoAsakura NekoAsakura added the AI-needs-explanation AI-assisted work that needs further explanation and follow up from the contributor label Oct 30, 2026
@bedevere-app

bedevere-app Bot commented Oct 30, 2026

Copy link
Copy Markdown

Thank you for your interest in contributing to Python. This is a community-driven project, and we want it to be a welcoming place to learn and collaborate.

Contributors are responsible for reviewing and understanding what they submit, checking its claims, and being able to explain changes in their own words. This helps reviewers focus on the contribution and leaves more time to support other contributors.

This contribution appears to have been authored with AI assistance. Please explain your contribution in your own words and describe how you checked its correctness.

Please read our guidelines for using AI tools.

@NekoAsakura NekoAsakura left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! Please keep the change minimal and focused, and it doesn't need a NEWS entry.

@timurzvural

Copy link
Copy Markdown
Author

Thanks — updated.

I removed the NEWS entry and left only the test change in Lib/test/test_external_inspection.py.

What was wrong: The test attached RemoteUnwinder as soon as the child PID was readable, then immediately took 10,000 samples. On a slow machine/buildbot, all of those samples could land during interpreter startup, before leaf() was on the stack. The later assertions then saw zero leaf frames and failed intermittently.

What the test change does: After attaching, it polls get_stack_trace() until some frame's funcname is "leaf". Only then does it run the existing 10,000-sample loop and the same check that a popping leaf frame is never labeled <native>.

How I checked it: Compared against the race described in #160986: the failure mode was "samples finish before leaf exists," so delaying the sample window until leaf appears removes that race without changing what the test asserts about native vs Python frames.

@johnslavik johnslavik added AI-guidelines-not-met The contribution does not meet our guidelines for using AI tools and is closed automatically. and removed AI-needs-explanation AI-assisted work that needs further explanation and follow up from the contributor labels Oct 31, 2026
@bedevere-app

bedevere-app Bot commented Oct 31, 2026

Copy link
Copy Markdown

Thank you for your interest in contributing to Python. This is a community-driven project, and we want it to be a welcoming place to learn and collaborate.

Contributors are responsible for reviewing and understanding what they submit, checking its claims, and being able to explain changes in their own words. This helps reviewers focus on the contribution and leaves more time to support other contributors.

We believe this contribution does not meet our guidelines for using AI tools, so we're closing it. If you think we've misunderstood your contribution, please let us know. You're welcome to explain your approach or ask questions about the guidelines.

Please read our guidelines for using AI tools.

@bedevere-app bedevere-app Bot closed this Oct 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI-guidelines-not-met The contribution does not meet our guidelines for using AI tools and is closed automatically. awaiting core review skip news tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test_popping_python_frame_is_not_native fails randomly on buildbots

3 participants