New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Thread local storage and PyGILState_* mucked up by os.fork() #46024
Comments
I got a report that one of the tests for processing
when run with a debug interpreter. This appears to be caused by the All that happens is that the parent process starts a subthread then With the normal interpreter I get
as expected, but with the debug interpreter I get
Notice that the child process is reusing a thread id that was The code raising the error seems to be in pystate.c:
_PyThreadState_Current = new;
/* It should not be possible for more than one thread state
to be used for a thread. Check this the best we can in
debug
builds.
*/
#if defined(Py_DEBUG) && defined(WITH_THREAD)
if (new) {
PyThreadState *check = PyGILState_GetThisThreadState();
if (check && check != new)
Py_FatalError("Invalid thread state for this
thread");
}
#endif
return old;
} It looks as though PyGILState_GetThisThreadState() is returning the I think the thread local storage implementation in thread.c should |
The included patch against python2.51 fixes the problem for me. |
Bug day task |
we need this in before 2.6 is released. |
Gregory, go ahead and apply and see if can stop the hell in the buildbots. |
Updated version of roudkerk's patch. Adds the new function to Note that Parser/intrcheck.c isn't used on my box, so it's completely roudkerk's original analysis is correct. The TLS is never informed that |
Incidentally, it doesn't seem necessary to reinitialize the lock. Posix (reinitializing is essentially harmless though, so in no way should this |
I applied this in r64212. |
The fix is required to run multiprocessing on Python 2.4 and 2.5, see test_connection (multiprocessing.tests.WithProcessesTestConnection) ... Linux on AMD64 with Python 2.5 svn --with-pydebug. |
I was wrong and the patch is right. Something is wrong in Martin, are you fine with the patch? fork-thread-patch-2 still applies |
Looks fine to me, somebody please backport it. I'm concerned about the memory leak that this may cause, though (IIUC): I think in the long run, we should allow to store a pointer to a release |
Since this is a Python 2.5.3 issue, I'm lowering to deferred blocker |
Committed fork-thread-patch-2 as r67736 into 2.5 branch. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: