[issue1402] Interpreter cleanup: order of _PyGILState_Fini and PyInterpreterState_Clear

Amaury Forgeot d'Arc report at bugs.python.org
Sat Nov 24 00:34:30 CET 2007


Amaury Forgeot d'Arc added the comment:

I managed to reproduce the problem consistently with the following code:

import ctypes, sys, time, thread

# Module globals are cleared before __del__ is run
# So save the functions in class dict
class C:
    ensure = ctypes.pythonapi.PyGILState_Ensure
    release = ctypes.pythonapi.PyGILState_Release
    def __del__(self):
        state = self.ensure()
        self.release(state)

def waitingThread():
    x = C()
    time.sleep(100)

thread.start_new_thread(waitingThread, ())
time.sleep(1)
sys.exit(42)


On exit, PyInterpreterState_Clear stops the sleeping thread and free its
local variables. But at this time _PyGILState_Fini has already been
called...

The initial patch also corrects this problem. I join another patch,
which adds the above code in a testcase.

Ready to check-in, but can someone have a look?

----------
nosy: +amaury.forgeotdarc
Added file: http://bugs.python.org/file8798/test_gilstate.patch

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue1402>
__________________________________
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_gilstate.patch
Type: application/octet-stream
Size: 1723 bytes
Desc: not available
Url : http://mail.python.org/pipermail/python-bugs-list/attachments/20071123/167e6eba/attachment.obj 


More information about the Python-bugs-list mailing list