Repository navigation
gh-161928: Fix spurious async for exit events in sys.monitoring - #162928
LUX-ETVERITAS wants to merge 2 commits into
Conversation
|
How much of the fix do you yourself understand and would explain to someone who doesn't know the bytecode? Do you understand the rationale why codex did some changes? |
|
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. |
Fixes #161928.
When an async iterator raises an exception such as
ValueError,sys.monitoringreports aBRANCH_RIGHTevent pointing past the loop even though execution never reaches that point. Emit the loop-exit event only when the exception matchesStopAsyncIteration. This preserves the order of the callback and stack cleanup on normal exhaustion.The regression test records
BRANCH_RIGHTevents for an async generator that yields once and then raisesValueError. It catches the extra event on main and passes with the fix. The adjacent test covers normal exhaustion.Verification included
test_monitoring, a reference-leak check for its async-for tests, andmake patchcheck. After rerunning the failures from the full local suite, onlytest_socket.test_host_resolution_bad_addressstill failed. The system Python also resolves the malformed hostname used by that test.Codex helped write the patch and run the tests.
async foremits BRANCH_RIGHT when__anext__raises an exception other than StopAsyncIteration #161928