[pygtk] PyGtk signals and python thread lock
Stephen George
steve_geo at optusnet.com.au
Fri Jul 17 06:27:41 WST 2009
Hi,
This all sounds complicated and I might be way off the mark, but I
thought your not meant to be draw on the GUI from another thread.
Usually when I have a threaded application (pyGTK only) that needs to
send signals across the threads I emit the signal with
gobject.idle_add(self.emit, "usb-connection-lost")
This seems to queue the signal to be run under the main threads idle
loop. Hence you keep the interaction with the GUI under the same thread
that it was created with.
Steve
Carlos Lacasta wrote:
> 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
>
>
>
> _______________________________________________
> pygtk mailing list pygtk at daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://faq.pygtk.org/
>
>
More information about the pygtk
mailing list