Repository navigation
gh-160676: Propagate monitoring callback errors from for loops - #160703
vankudothuadhinaik wants to merge 5 commits into
Conversation
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
NekoAsakura
left a comment
There was a problem hiding this comment.
_ITER_NEXT_INLINE needs to be covered in the test.
| if (_PyErr_Occurred(tstate)) { | ||
| if (_PyErr_ExceptionMatches(tstate, PyExc_StopIteration)) { | ||
| _PyEval_MonitorRaise(tstate, frame, frame->instr_ptr); | ||
| if (_PyEval_MonitorRaise(tstate, frame, frame->instr_ptr) < 0) { |
There was a problem hiding this comment.
Escaping calls shouldn't be inside control flow statements. See #122693 (comment).
There was a problem hiding this comment.
Addressed in the current head: _PyEval_MonitorRaise() is called outside the control-flow branch and its result is assigned to err before branching, following the escaping-call convention. The generated executor file was regenerated and verified consistent. I also added tier-2 coverage that locates _ITER_NEXT_INLINE and checks callback-error propagation. The tier-2 interpreter CI job and its test_monitoring module passed; the job summary does not expose this individual method's pass/skip result, so I am not claiming more than the logs establish. Could you please re-review when convenient?
|
Follow-up on the review feedback:
Could you please re-review the updated implementation and test when convenient? |
NekoAsakura
left a comment
There was a problem hiding this comment.
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 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.
| if executor is None: | ||
| self.skipTest("requires _ITER_NEXT_INLINE executor") |
There was a problem hiding this comment.
Please explain in detail what this part of the test does.
| # Warm up the loop before enabling monitoring, so the callback run | ||
| # executes the tier-2 executor rather than creating it. |
There was a problem hiding this comment.
This comment is very LLM-esque. Either simplify it to one line or remove it.
Fixes gh-160676.
Summary
When a
sys.monitoringRAISE callback raises while reportingStopIterationfrom aforloop, the callback exception can be swallowed by the iterator-exhaustion path._PyEval_MonitorRaise()return the monitoring callback result._PyForIter_VirtualIteratorNext()and the tier-2_ITER_NEXT_INLINEpath.Python/executor_cases.c.h.RuntimeErrorforStopIteration.Validation
test_monitoringsuite: 101 passed.make -j2: passed.make regen-cases: generatedPython/executor_cases.c.hmatched the checked-in worktree version byte-for-byte.git diff --check: passed.Limitations
The regression test demonstrated the tier-1 path. Tier-2 runtime coverage was not demonstrated because the available build had no experimental JIT support and active monitoring instrumentation avoided executor execution. Native macOS testing was not performed.