diff -r 8527427914a2 Include/pystate.h --- a/Include/pystate.h Sat Jun 11 09:50:21 2011 -0500 +++ b/Include/pystate.h Thu Jan 31 22:33:04 2013 +0100 @@ -180,6 +180,8 @@ */ PyAPI_FUNC(PyObject *) _PyThread_CurrentFrames(void); +PyAPI_FUNC(void) _PyThread_AfterFork(void); + /* Routines for advanced debuggers, requested by David Beazley. Don't use unless you know what you are doing! */ PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_Head(void); diff -r 8527427914a2 Python/ceval.c --- a/Python/ceval.c Sat Jun 11 09:50:21 2011 -0500 +++ b/Python/ceval.c Thu Jan 31 22:33:04 2013 +0100 @@ -326,6 +326,8 @@ else Py_DECREF(result); Py_DECREF(threading); + + _PyThread_AfterFork(); } #endif diff -r 8527427914a2 Python/pystate.c --- a/Python/pystate.c Sat Jun 11 09:50:21 2011 -0500 +++ b/Python/pystate.c Thu Jan 31 22:33:04 2013 +0100 @@ -496,6 +496,14 @@ /* Python "auto thread state" API. */ #ifdef WITH_THREAD +void +_PyThread_AfterFork(void) +{ + PyThreadState *tstate = _PyThreadState_Current; + while (tstate->next) + PyThreadState_Delete(tstate->next); +} + /* Keep this as a static, as it is not reliable! It can only ever be compared to the state for the *current* thread. * If not equal, then it doesn't matter that the actual