[Python-Dev] segfault when using PyGILState_Ensure/Release in Python2.3.4

Travis E. Oliphant oliphant.travis at ieee.org
Fri Jul 21 09:42:51 CEST 2006


I'm hoping somebody here can help me with an error I'm getting in Python 
  2.3.4 but not in Python 2.4.2 when I use PyGILState_Ensure in NumPy on 
Linux.

Perhaps somebody can point out what I'm doing wrong because while I've 
tried to understand the threading API it can be a bit confusing and 
maybe I'm doing it wrong.

Right now, I've had to disable threading support in NumPy for Python 2.3 
which is a bit annoying.

The problem shows up when I've released the GIL using 
PyEval_SaveThread() in one section of code.  Then the code calls 
functions that don't involve the Python C-API.

Then another function sometimes requires use of the C-API to set a 
Python Error or issue a warning.   So I call:

_save = PyGILState_Ensure();

<Use Python C-API to issue an error or warning>

Finally, before exiting this function

PyGILState_Release(_save);

is called.   Later when control returns to the original caller that 
released the GIL, PyEval_RestoreThread() is called.  But the segfault 
seems to be happening on the call to PyGILState_Release(_save);

All of this works fine when it runs under Python 2.4.2, but under Python 
2.3.4 I get a segfault.

Does anybody have any ideas?   Thanks very much.



More information about the Python-Dev mailing list