Repository navigation
Ref tests failure on test_monitoring #103845
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Apr 25, 2023 The direct trigger here is
sys.monitoring.restart_events()../python -m test test_monitoring -R :effectively executes the test suite twice, so there's asys.monitoring.restart_events()call between two executions of the failed test. Here's a smaller demo:Demo
import sys def f(): def func(): a = 1 b = 2 E = sys.monitoring.events TOOL_ID = 2 sys.monitoring.use_tool_id(TOOL_ID, "test") sys.monitoring.register_callback(TOOL_ID, E.LINE, lambda *args: print(args)) sys.monitoring.register_callback(TOOL_ID, E.INSTRUCTION, lambda *args: print(args)) sys.monitoring.set_events(TOOL_ID, E.LINE | E.INSTRUCTION) func() sys.monitoring.set_events(TOOL_ID, 0) sys.monitoring.restart_events() sys.monitoring.set_events(TOOL_ID, E.LINE | E.INSTRUCTION) func() sys.monitoring.set_events(TOOL_ID, 0) f()
When
sys.monitoring.restart_events()is called, the monitoring tools are labeled so each code object could be updated. However, in_Py_Instrument(), we are doing separate loops for line & instruction events. So if we restart with both line and instruction events active on the code object we would have:- Remove line instrumentation
- Add line instrumentation
- Remove instruction instrumentation(!! line instrumentation is removed here !!)
- Add instruction instrumentation
So the line instrumentations on the code object will be removed and no line event will be generated. This could be confirmed with
dis.dis(code, adaptive=True)- noINSTRUMENTED_LINEopcode, insteadINSTRUMENTED_INSTRUCTIONis there.The fix could be simply to do remove first, then add. I had a prototype in #103851 and it solved the original issue. I also added a regression test.
Reacted by sunmy2019- added a commit that references this issue
on Apr 25, 2023 - added a commit that references this issue
on May 3, 2023 Appears to be fixed.
I ran./python -m test -F test_monitoring
which made it to 2000 repetitions before I killed it.@sunmy2019 can you confirm?
Confirmed and closed
Tested on cef542c, GCC 11.3 Ubuntu 22.04
Error Log
Looks like the behavior is changed when using
-R :?CC: @markshannon
Linked PRs