diff --git a/Python/pystate.c b/Python/pystate.c index db2ce878af64ec3..264191f943e81d4 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -2,6 +2,7 @@ /* Thread and interpreter state structures and their interfaces */ #include "Python.h" +#include "objimpl.h" #include "pycore_ceval.h" #include "pycore_code.h" // stats #include "pycore_frame.h" @@ -1388,6 +1389,10 @@ PyThreadState_Next(PyThreadState *tstate) { PyObject * _PyThread_CurrentFrames(void) { + // Disable the GC as this can cause a deadlock the interpreter. + // See issues 116969 and 106883. + PyGC_Disable(); + PyThreadState *tstate = _PyThreadState_GET(); if (_PySys_Audit(tstate, "sys._current_frames", NULL) < 0) { return NULL; @@ -1440,12 +1445,20 @@ _PyThread_CurrentFrames(void) done: HEAD_UNLOCK(runtime); + + // Once we release the runtime, the GC can be reenabled. + PyGC_Enable(); + return result; } PyObject * _PyThread_CurrentExceptions(void) { + // Disable the GC as this can cause a deadlock the interpreter. + // See issues 116969 and 106883. + PyGC_Disable(); + PyThreadState *tstate = _PyThreadState_GET(); _Py_EnsureTstateNotNULL(tstate); @@ -1499,6 +1512,10 @@ _PyThread_CurrentExceptions(void) done: HEAD_UNLOCK(runtime); + + // Once we release the runtime, the GC can be reenabled. + PyGC_Enable(); + return result; }