Repository navigation
gh-158121: Preserve instruction events when line monitoring is disabled - #158456
Conversation
|
Looks good to me, but I'd appreciate a review from @gaogaotiantian before merging |
|
@gaogaotiantian Mark mentioned he'd appreciate your review before merging. When you have a chance, would you mind taking a look? Happy to address anything you spot. Thanks! |
…ration Address review feedback by documenting the per-thread call records and multiline assignment, parameterizing both monitoring tool IDs, and placing the restoration comment before MODIFY_BYTECODE. Validation: Windows x64 Debug test_monitoring (99 tests); free-threaded Debug test_monitoring and test_free_threading.test_monitoring (113 tests); Ruff, patchcheck, and git diff --check.
|
@gaogaotiantian Thanks for the review! Addressed all four comments in f7e198c: moved the C comment before bytecode restoration, explained the nested thread/call records, documented the multiline assignment's backward line-event coverage, and made both Monitoring tests pass on standard and free-threaded debug builds (99 and 113 tests, respectively). Ready for another look when you have time. |
|
@gaogaotiantian Just following up on the review updates in f7e198c. Could you take another look when you have a chance? Thanks! |
|
Hi @gaogaotiantian, just checking in on the review updates in f7e198c. Your four comments have been addressed, and CI is passing. When you have a chance, could you take another look and let me know if anything else is needed before merging? Thanks again for your time! |
|
Thanks @limadog9 for the PR, and @gaogaotiantian for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15. |
|
Sorry, @limadog9 and @gaogaotiantian, I could not cleanly backport this to Please backport manually with cherry_picker, see the devguide for more information. |
|
GH-159733 is a backport of this pull request to the 3.15 branch. |
|
Sorry I've been super busy last 2 weeks. Thank you for fixing this! |
|
GH-159741 is a backport of this pull request to the 3.14 branch. |
Fixes #158121.
When the last LINE callback returns
sys.monitoring.DISABLE, the line metadata is updated to the underlying opcode. Dispatching that saved opcode skips the INSTRUCTION event for the current instruction even though instruction monitoring remains enabled. Check forINSTRUMENTED_INSTRUCTIONin the current bytecode before using the saved opcode, while retaining the existing fallback when callbacks change monitoring.Also defer updating the shared line metadata until every thread-local bytecode copy has been restored. Otherwise, later copies lose their INSTRUCTION wrappers and keep missing events on subsequent calls in free-threaded builds.
Regression tests cover global/local events, the same/separate tools, repeated calls,
restart_events(), and two existing worker-thread bytecode copies. The first regression fails on unmodified main in both builds; the threaded regression also fails with only the dispatch fix.Validation on Windows x64, built from main at
596d923with this patch:test_free_threading.test_monitoringpassed (1,613 test cases; expected skips).python_d.exe -m test -R 3:3 test_monitoringpassed with no reference leaks.patchcheck, Ruff, NEWS reStructuredText lint, andgit diff --checkpassed.The complete CPython test suite and non-Windows builds were not run locally.