Mercurial > cpython-lru_cache-weakref
diff Python/ceval.c @ 48274:43fa50b9eb12 2.5
Backport of r65032 from trunk
Fixes Issue #874900: after an os.fork() call the threading module state is cleaned
up in the child process to prevent deadlock and report proper thread counts
if the new process uses the threading module.
| author | Gregory P. Smith <greg@mad-scientist.com> |
|---|---|
| date | Sun, 17 Aug 2008 23:01:11 +0000 |
| parents | 60fd0886811c |
| children | 694d04ed2b43 |
line wrap: on
line diff
--- a/Python/ceval.c Sun Aug 17 09:49:10 2008 +0000 +++ b/Python/ceval.c Sun Aug 17 23:01:11 2008 +0000 @@ -272,6 +272,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 @@ -281,6 +284,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
