Index: Python/ceval.c =================================================================== --- Python/ceval.c (revision 64788) +++ Python/ceval.c (working copy) @@ -274,6 +274,9 @@ void PyEval_ReInitThreads(void) { + PyObject *threading, *lock; + PyThreadState *tstate; + if (!interpreter_lock) return; /*XXX Can't use PyThread_free_lock here because it does too @@ -283,6 +286,32 @@ interpreter_lock = PyThread_allocate_lock(); PyThread_acquire_lock(interpreter_lock, 1); main_thread = PyThread_get_thread_ident(); + + /* Reset threading._active_limbo_lock, in case we forked just + * when a thread was starting of stopping + */ + + tstate = PyThreadState_GET(); + threading = PyMapping_GetItemString(tstate->interp->modules, + "threading"); + if (threading == NULL) { + /* threading not imported */ + PyErr_Clear(); + return; + } + lock = PyObject_GetAttrString(threading, "_active_limbo_lock"); + if (lock == NULL) + PyErr_WriteUnraisable(threading); + else { + PyObject *res = PyObject_CallMethod(lock, "release", NULL); + if (res == NULL) + /* Ignore the "release unlocked lock" error */ + PyErr_Clear(); + else + Py_DECREF(res); + Py_DECREF(lock); + } + Py_DECREF(threading); } #endif