Skip to content
Closed
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix a crash that can occur in free-threading builds when
``sys._setprofileallthreads`` or ``sys._settraceallthreads`` changes the
profile function underneath a running thread.
8 changes: 7 additions & 1 deletion Python/legacy_tracing.c
Original file line number Diff line number Diff line change
Expand Up @@ -484,13 +484,19 @@ setup_profile(PyThreadState *tstate, Py_tracefunc func, PyObject *arg, PyObject
}
}

_PyEval_StopTheWorld(tstate->interp);

int delta = (func != NULL) - (tstate->c_profilefunc != NULL);
tstate->c_profilefunc = func;
*old_profileobj = tstate->c_profileobj;
tstate->c_profileobj = Py_XNewRef(arg);
tstate->interp->sys_profiling_threads += delta;
assert(tstate->interp->sys_profiling_threads >= 0);
return tstate->interp->sys_profiling_threads;
Py_ssize_t ret = tstate->interp->sys_profiling_threads;

_PyEval_StartTheWorld(tstate->interp);

return ret;
}

int
Expand Down
Loading