diff --git a/Python/perf_trampoline.c b/Python/perf_trampoline.c index f144f7d436fe68d..9b8249419970abc 100644 --- a/Python/perf_trampoline.c +++ b/Python/perf_trampoline.c @@ -471,6 +471,16 @@ _PyPerfTrampoline_SetCallbacks(_PyPerf_Callbacks *callbacks) return 0; } +#ifdef PY_HAVE_PERF_TRAMPOLINE +static void +set_eval_frame(PyThreadState *tstate, _PyFrameEvalFunction eval_frame) +{ + _PyEval_StopTheWorld(tstate->interp); + tstate->interp->eval_frame = eval_frame; + _PyEval_StartTheWorld(tstate->interp); +} +#endif + int _PyPerfTrampoline_Init(int activate) { @@ -484,11 +494,11 @@ _PyPerfTrampoline_Init(int activate) return -1; } if (!activate) { - tstate->interp->eval_frame = NULL; + set_eval_frame(tstate, NULL); perf_status = PERF_STATUS_NO_INIT; } else { - tstate->interp->eval_frame = py_trampoline_evaluator; + set_eval_frame(tstate, py_trampoline_evaluator); if (new_code_arena() < 0) { return -1; } @@ -514,7 +524,7 @@ _PyPerfTrampoline_Fini(void) } PyThreadState *tstate = _PyThreadState_GET(); if (tstate->interp->eval_frame == py_trampoline_evaluator) { - tstate->interp->eval_frame = NULL; + set_eval_frame(tstate, NULL); } if (perf_status == PERF_STATUS_OK) { trampoline_api.free_state(trampoline_api.state); diff --git a/Python/pystate.c b/Python/pystate.c index 3ceae229f75cd09..839413a65a42fb7 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -2838,7 +2838,9 @@ _PyInterpreterState_SetEvalFrameFunc(PyInterpreterState *interp, } #endif RARE_EVENT_INC(set_eval_frame_func); + _PyEval_StopTheWorld(interp); interp->eval_frame = eval_frame; + _PyEval_StartTheWorld(interp); }