summaryrefslogtreecommitdiff
path: root/Python
diff options
context:
space:
mode:
authorGregory P. Smith <greg@mad-scientist.com>2008-08-17 23:01:11 +0000
committerGregory P. Smith <greg@mad-scientist.com>2008-08-17 23:01:11 +0000
commit5e8dc97a098766a566b07df241c524fbd56d34ac (patch)
tree2d9d31372c73d994c7cc2938177b70a272cf8580 /Python
parent1d63a45d0d25acec0174bb291e6cd4c7c0d7c00d (diff)
downloadcpython-git-5e8dc97a098766a566b07df241c524fbd56d34ac.tar.gz
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.
Diffstat (limited to 'Python')
-rw-r--r--Python/ceval.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 9bc147b78d..ddfe3c48ea 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -272,6 +272,9 @@ PyEval_ReleaseThread(PyThreadState *tstate)
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 @@ PyEval_ReInitThreads(void)
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