Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Lib/test/test_free_threading/test_monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ def test_instrumentation(self):
break

self.during_threads()
# Sleep to avoid setting monitoring events too rapidly and
# overflowing the global version counter
time.sleep(0.0001)

self.after_test()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix inconsistent state when enabling or disabling monitoring events too many
times.
2 changes: 1 addition & 1 deletion Python/instrumentation.c
Original file line number Diff line number Diff line change
Expand Up @@ -2019,12 +2019,12 @@ _PyMonitoring_SetEvents(int tool_id, _PyMonitoringEventSet events)
if (existing_events == events) {
return 0;
}
set_events(&interp->monitors, tool_id, events);
uint32_t new_version = global_version(interp) + MONITORING_VERSION_INCREMENT;
if (new_version == 0) {
PyErr_Format(PyExc_OverflowError, "events set too many times");
return -1;
}
set_events(&interp->monitors, tool_id, events);
set_global_version(tstate, new_version);
#ifdef _Py_TIER2
_Py_Executors_InvalidateAll(interp, 1);
Expand Down
Loading