[pygtk] PyGtk signals and python thread lock
Carlos Lacasta
Carlos.Lacasta at ific.uv.es
Thu Jul 16 21:21:52 WST 2009
Hello,
I am developing a C++ multithreaded application, under linux, with
embedded python. Some of the python code has to be executed in different
threads and to solve this I release the python thread lock in the main
thread in a sequence like:
Py_Initialize();
if (! PyEval_ThreadsInitialized() )
{
PyThreadState *py_tstate = 0;
PyEval_InitThreads();
py_tstate = PyGILState_GetThisThreadState();
PyEval_ReleaseThread(py_tstate);
}
All the embedded python code is executed like
PyGILState_STATE gilstate;
gilstate = PyGILState_Ensure();
.... call python API functions ...
PyGILState_Release(gilstate);
in any of the threads.
This works perfectly OK until some of the python code uses PyGTK to
define a GUI for a particular task and the code connects to signals
emitted by the PyGTK widgets. When that happens the application crashes
immediately because nobody has the python thread lock. Is there a way of
acquiring the python thread lock before having PyGTK calling the
callbacks and release it right after ?
Regards,
Carlos
More information about the pygtk
mailing list