Problems with PyGILState_Ensure () and PyGILState_Release ()

Mathias Mamsch Domoran at
Fri Aug 13 13:49:09 CEST 2004

Hi all,

i am writing a python extension in c++.   In the extension a c++ thread
calls back into python. I did it like this:

---- c++ code ----
PyGILState_STATE gstate;
gstate = PyGILState_Ensure ();

... do some work ...
// call the python callback (Func)
result = PyEval_CallObject(Func, arglist);
... so some cleanup ...

PyGILState_Release (gstate);

the callback is executed properly, but the PyGILState_Release gives me the
following error:
"Fatal Python error: PyThreadState_Delete: tstate is still current"

What can be wrong here? Any suggestions?
In my understanding this error should not occur ... Is this a known bug
maybe? I am using Python 2.4a1 under windows.

Thanks in advance, Mathias Mamsch

More information about the Python-list mailing list