Skip to content

gh-159645: Fix --async-aware profiles showing event loop frames under tasks - #159679

Merged
pablogsal merged 6 commits into
python:mainfrom
deadlovelll:gh-159645-profiling
Nov 24, 2026
Merged

pablogsal merged 6 commits into
python:mainfrom
deadlovelll:gh-159645-profiling

Conversation

@deadlovelll

Copy link
Copy Markdown
Contributor

Fix --async-aware profiles showing event loop frames under tasks

See gh-159645

@pablogsal pablogsal 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.

hummm I don’t think this is a correct fix. FRAME_EXECUTING does not guarantee that the task frame is in the thread stack.

For example, when spin() yields at await asyncio.sleep(0), _YIELD_VALUE removes its frame before it updates gi_frame_state. A sample between those writes sees FRAME_EXECUTING, but the thread stack already leads back to the event loop:

Handle._run -> BaseEventLoop._run_once -> BaseEventLoop.run_forever

parse_async_frame_chain() never reaches the spin() frame, yet it returns success. Those event-loop frames then replace the task’s logical coroutine chain. This also affects --blocking, since the process can stop between those writes.

@bedevere-app

bedevere-app Bot commented Oct 18, 2026

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@deadlovelll

Copy link
Copy Markdown
Contributor Author

hummm I don’t think this is a correct fix. FRAME_EXECUTING does not guarantee that the task frame is in the thread stack.

For example, when spin() yields at await asyncio.sleep(0), _YIELD_VALUE removes its frame before it updates gi_frame_state. A sample between those writes sees FRAME_EXECUTING, but the thread stack already leads back to the event loop:

Handle._run -> BaseEventLoop._run_once -> BaseEventLoop.run_forever

parse_async_frame_chain() never reaches the spin() frame, yet it returns success. Those event-loop frames then replace the task’s logical coroutine chain. This also affects --blocking, since the process can stop between those writes.

Thanks! I'll think about proper solution

@deadlovelll

Copy link
Copy Markdown
Contributor Author

hey @pablogsal, sorry for delay, i changed the approach, please review again

@deadlovelll
deadlovelll requested a review from pablogsal October 31, 2026 12:38
@deadlovelll

Copy link
Copy Markdown
Contributor Author

@pablogsal just a gentle ping. Could you take another look when you have a chance? =)

@pablogsal pablogsal added the needs backport to 3.15 bugs and security fixes label Nov 24, 2026

@pablogsal pablogsal 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.

LGTM! Thanks for the update, Timofei!

@pablogsal
pablogsal enabled auto-merge (squash) November 24, 2026 12:34
@pablogsal pablogsal added the needs backport to 3.14 bugs and security fixes label Nov 24, 2026
@pablogsal
pablogsal merged commit 922413e into python:main Nov 24, 2026
66 of 67 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @deadlovelll for the PR, and @pablogsal for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Nov 24, 2026

Copy link
Copy Markdown

GH-162551 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Nov 24, 2026
@miss-islington-app

Copy link
Copy Markdown

Sorry, @deadlovelll and @pablogsal, I could not cleanly backport this to 3.14 due to a conflict.

Please backport manually with cherry_picker, see the devguide for more information.

cherry_picker 922413ea388cf8cd35f0c19c3ac005ea7dc92d1d 3.14

@bedevere-app

bedevere-app Bot commented Nov 24, 2026

Copy link
Copy Markdown

GH-162552 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants