[pygtk] idle_add vs. threads_enter/threads_leave
Pietro Battiston
me at pietrobattiston.it
Mon Jul 5 17:53:20 WST 2010
Il giorno lun, 05/07/2010 alle 16.32 +0800, Jason Heeris ha scritto:
> Hi,
>
> I've been reading some conflicting advice on PyGTK and threading
> recently, probably because the API went through some fairly rapid
> changes recently.
>
> I'm a bit confused about the following points (consider them in
> context of PyGTK/PyGObject unstable, ie. 2.17/2.21 respectively):
>
> 1. If I want to do async activity in a new Python thread spawned
> from the main loop, I need to have called glib.threads_init() *before*
> starting the main loop, right? But what about gtk.gdk.threads_init()?
> 2. Any GTK interaction, such as emitting a signal from this new
> thread, must be either:
> a. done via glib.idle_add (if I'm happy to let GTK do it
> whenever it next feels like it), -OR-
> b. wrapped in gtk.gdk.threads_enter()/...leave(), -OR-
> c. in a "with: gtk.gdk.lock:" block (equivalent to 2.b)
Apart from 2.c, I guess
http://faq.pygtk.org/index.py?file=faq20.006.htp&req=show
is clear enough?
> 3. I don't need to do the threads_enter/leave (or use the context
> manager) if I only use glib.idle_add (or timeout_add, etc)
No, you don't. If you don't really need threads, life is much simpler.
Cheers,
Pietro
More information about the pygtk
mailing list