diff -r bbfc65d05588 Modules/signalmodule.c --- a/Modules/signalmodule.c Thu Apr 07 10:48:29 2011 -0400 +++ b/Modules/signalmodule.c Tue Apr 26 21:42:14 2011 +0200 @@ -76,6 +76,9 @@ #ifdef WITH_THREAD #include /* For pid_t */ #include "pythread.h" + +extern void _PyGILState_Reinit(void); + static long main_thread; static pid_t main_pid; #endif @@ -985,6 +988,7 @@ PyOS_AfterFork(void) { #ifdef WITH_THREAD + _PyGILState_Reinit(); PyEval_ReInitThreads(); main_thread = PyThread_get_thread_ident(); main_pid = getpid(); diff -r bbfc65d05588 Python/pystate.c --- a/Python/pystate.c Thu Apr 07 10:48:29 2011 -0400 +++ b/Python/pystate.c Tue Apr 26 21:42:14 2011 +0200 @@ -585,6 +585,23 @@ autoInterpreterState = NULL; } +/* Reset the TLS key - called by PyOS_AfterFork. + * This should not be necessary, but some - buggy - pthread implementations + * don't flush TLS on fork, see issue #10517. + */ +void +_PyGILState_Reinit(void) +{ + PyThreadState *tstate = PyGILState_GetThisThreadState(); + PyThread_delete_key(autoTLSkey); + if ((autoTLSkey = PyThread_create_key()) == -1) + Py_FatalError("Could not allocate TLS entry"); + + /* re-associate the current thread state with the new key */ + if (PyThread_set_key_value(autoTLSkey, (void *)tstate) < 0) + Py_FatalError("Couldn't create autoTLSkey mapping"); +} + /* When a thread state is created for a thread by some mechanism other than PyGILState_Ensure, it's important that the GILState machinery knows about it so it doesn't try to create another thread state for the thread (this is