[issue1402] Interpreter cleanup: order of _PyGILState_Fini and PyInterpreterState_Clear

Ronald Oussoren report at bugs.python.org
Tue Nov 27 06:38:44 CET 2007


Ronald Oussoren added the comment:

This is not a mac-specific issue, the script happens to be mac-specific 
because that's how I found the issue.

Amaury's patch adds a unittest that reproduces the problem in a 
platform-indepenent way using ctypes.

The _PyGILState_Fini function might cause user code to run as well, it 
removes the thread-local variable that contains the PyThreadState for 
threads, and that contains some Python objects that might contain 
arbitrary values (such as the last exception value). I guess that means 
that a variation on Amaury's patch would cause a patched interpreter to 
crash (create on instance of 'C' as an attribute on an exception, e.g. 
raise ValueError(C()) in the second thread). 

BTW. I would be very uncomfortable if my patch were applied without 
review from someone that knows his way around the threading code.  

BTW2. I have a workaround for my initial issue (the crash in 
threads.py): if I add an atexit handler that performs some cleanup in 
PyObjC the problem goes away.

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue1402>
__________________________________


More information about the Python-bugs-list mailing list