Repository navigation
gh-162027: Fix branch monitoring events for async comprehensions and loops - #162033
Closed
itxtarun2727 wants to merge 1 commit into
Closed
itxtarun2727 wants to merge 1 commit into
itxtarun2727 wants to merge 1 commit into
Conversation
itxtarun2727
requested review from
iritkatriel and
markshannon
as code owners
November 15, 2026 08:17
|
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary & Problem Description
In
sys.monitoring, branch events for asynchronous loops were erroneous in two scenarios:[x async for x in agen()]never emittedBRANCH_LEFTand callingco_branches()aborted with an assertion failure ininstrumentation.c:3183becauseNOT_TAKENwas not generated afterEND_SEND.async forloops: When basic blocks were reordered (e.g. moving coldCLEANUP_THROWexception blocks), the distance betweenSENDandEND_SENDdiffered from the hardcodedEND_SEND_OFFSET 6inassemble.c. This causedEND_ASYNC_FOR'sopargto point toCLEANUP_THROWinstead ofEND_SEND, resulting in mismatched source offsets and debug assertion failures.Solution
Python/codegen.c, updatedcodegen_add_yield_fromto export theexitlabel pointing directly toEND_SEND.END_ASYNC_FORdirectly toend_sendin bothcodegen_async_for()andcodegen_async_comprehension_generator().ADDOP(c, loc, NOT_TAKEN)tocodegen_async_comprehension_generator().Python/assemble.c, removed#define END_SEND_OFFSET 6and calculated the backwards jump offset directly fromEND_SEND.Lib/test/test_monitoring.py.Verification
BRANCH_LEFT/BRANCH_RIGHTevents matchingco_branches().PCbuild\amd64\python_d.exe -m test test_monitoring -v(104/104 tests passed).PCbuild\amd64\python_d.exe -m test test_monitoring -R :(0 reference leaks).pre-commit runpassed cleanly.Fixes #162027
async forloop #162027