Skip to content

Commit 589382b

Browse files
[3.13] gh-131141: fix data race in instrumentation while registering callback (#131166)
1 parent 589f422 commit 589382b

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix data race in :data:`sys.monitoring` instrumentation while registering callback.

Python/instrumentation.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -1399,9 +1399,10 @@ _PyMonitoring_RegisterCallback(int tool_id, int event_id, PyObject *obj)
13991399
PyInterpreterState *is = _PyInterpreterState_GET();
14001400
assert(0 <= tool_id && tool_id < PY_MONITORING_TOOL_IDS);
14011401
assert(0 <= event_id && event_id < _PY_MONITORING_EVENTS);
1402-
PyObject *callback = _Py_atomic_exchange_ptr(&is->monitoring_callables[tool_id][event_id],
1403-
Py_XNewRef(obj));
1404-
1402+
_PyEval_StopTheWorld(is);
1403+
PyObject *callback = is->monitoring_callables[tool_id][event_id];
1404+
is->monitoring_callables[tool_id][event_id] = Py_XNewRef(obj);
1405+
_PyEval_StartTheWorld(is);
14051406
return callback;
14061407
}
14071408

0 commit comments

Comments
 (0)