[pygtk] PyGtk signals and python thread lock
Carlos Lacasta
Carlos.Lacasta at ific.uv.es
Fri Jul 17 15:07:20 WST 2009
Hi,
Thanks for that. Yes, this is what one usually does. My problem,
however, is that I do not have the python thread lock even if I queue
the signal processing with an idle function in the main loop as you
suggest.
My question is whether there is, or if I can implement in an easy way, a
sort of hook that acquires the lock before calling the callback function
and releases it right after.
Cheers,
Carlos
On Fri, 2009-07-17 at 08:27 +1000, Stephen George wrote:
> 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/
> >
> >
--
___________________________________________________________________
Carlos Lacasta
^^^^^^^^^^^^^^^
Inst. de Fisica Corpuscular (IFIC)
Edificio Institutos de Investigacion
P.O. Box 22085
E-46071 VALENCIA
Spain
Tel.: +34 96 354 3490
Fax.: +34 96 354 3488
Carlos.Lacasta at ific.uv.es
___________________________________________________________________
More information about the pygtk
mailing list