Mercurial > cpython-lru_cache-weakref
diff Python/ceval.c @ 47985:09beb96ba20d legacy-trunk
Apply patch for 874900: threading module can deadlock after fork
| author | Jesse Noller <jnoller@gmail.com> |
|---|---|
| date | Wed, 16 Jul 2008 20:03:47 +0000 |
| parents | c93596ec1d3d |
| children | 30485bc17268 |
line wrap: on
line diff
--- a/Python/ceval.c Wed Jul 16 18:48:35 2008 +0000 +++ b/Python/ceval.c Wed Jul 16 20:03:47 2008 +0000 @@ -274,6 +274,9 @@ void PyEval_ReInitThreads(void) { + PyObject *threading, *result; + PyThreadState *tstate; + if (!interpreter_lock) return; /*XXX Can't use PyThread_free_lock here because it does too @@ -283,6 +286,23 @@ interpreter_lock = PyThread_allocate_lock(); PyThread_acquire_lock(interpreter_lock, 1); main_thread = PyThread_get_thread_ident(); + + /* Update the threading module with the new state. + */ + tstate = PyThreadState_GET(); + threading = PyMapping_GetItemString(tstate->interp->modules, + "threading"); + if (threading == NULL) { + /* threading not imported */ + PyErr_Clear(); + return; + } + result = PyObject_CallMethod(threading, "_after_fork", NULL); + if (result == NULL) + PyErr_WriteUnraisable(threading); + else + Py_DECREF(result); + Py_DECREF(threading); } #endif
