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.
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to