Skip to content

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

Open
deadlovelll wants to merge 2 commits into
python:mainfrom
deadlovelll:gh-159645-profiling
Open

deadlovelll wants to merge 2 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

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.

2 participants