[Python-Dev] pystate.c changes for Python 2.4.2

Gabriel Becedillas gabriel.becedillas at corest.com
Thu Jan 12 17:47:31 CET 2006


Hi,
At the company I work for, we've embedded Python in C++ application we 
develop. Since our upgrade to Python 2.4.2 from 2.4.1 we started hitting 
Py_FatalError("Invalid thread state for this thread") when using debug 
builds.
We use both multiple interpreters and thread states.

I think the problem is that PyThreadState_Delete (which is used when I
destroy thread states and interpreters) is not making the same clean up
that PyThreadState_DeleteCurrent is doing (which is used when we create 
threads from python code). If a thread id is reused (obviously not 
between two running threads), and the previous thread used 
PyThreadState_Delete instead of PyThreadState_DeleteCurrent, then an old 
and invalid value for autoTLSkey is still stored, and that is
triggering the Py_FatalError when a call to PyThreadState_Swap is made.
If I add this code at the end of PyThreadState_Delete:

if (autoTLSkey && PyThread_get_key_value(autoTLSkey) == tstate)
	PyThread_delete_key_value(autoTLSkey);

then everything works fine.
Could you please confirm if this is a bug ?
Thanks a lot and have a nice day.


More information about the Python-Dev mailing list