@@ -484,13 +484,16 @@ setup_profile(PyThreadState *tstate, Py_tracefunc func, PyObject *arg, PyObject
484484 }
485485 }
486486
487+ _PyEval_StopTheWorld (tstate -> interp );
487488 int delta = (func != NULL ) - (tstate -> c_profilefunc != NULL );
488489 tstate -> c_profilefunc = func ;
489490 * old_profileobj = tstate -> c_profileobj ;
490491 tstate -> c_profileobj = Py_XNewRef (arg );
491492 tstate -> interp -> sys_profiling_threads += delta ;
492493 assert (tstate -> interp -> sys_profiling_threads >= 0 );
493- return tstate -> interp -> sys_profiling_threads ;
494+ Py_ssize_t profiling_threads = tstate -> interp -> sys_profiling_threads ;
495+ _PyEval_StartTheWorld (tstate -> interp );
496+ return profiling_threads ;
494497}
495498
496499int
@@ -581,13 +584,16 @@ setup_tracing(PyThreadState *tstate, Py_tracefunc func, PyObject *arg, PyObject
581584 }
582585 }
583586
587+ _PyEval_StopTheWorld (tstate -> interp );
584588 int delta = (func != NULL ) - (tstate -> c_tracefunc != NULL );
585589 tstate -> c_tracefunc = func ;
586590 * old_traceobj = tstate -> c_traceobj ;
587591 tstate -> c_traceobj = Py_XNewRef (arg );
588592 tstate -> interp -> sys_tracing_threads += delta ;
589593 assert (tstate -> interp -> sys_tracing_threads >= 0 );
590- return tstate -> interp -> sys_tracing_threads ;
594+ Py_ssize_t tracing_threads = tstate -> interp -> sys_tracing_threads ;
595+ _PyEval_StartTheWorld (tstate -> interp );
596+ return tracing_threads ;
591597}
592598
593599int
0 commit comments