Il giorno lun, 05/07/2010 alle 18.09 +0800, Jason Heeris ha scritto:
> On 5 July 2010 17:53, Pietro Battiston <[email protected]> wrote:
> > Apart from 2.c, I guess
> > http://faq.pygtk.org/index.py?file=faq20.006.htp&req=show
> > is clear enough?
>
> It's clear, except I can't tell if it applies to PyGObject 2.20 or
> 2.21 (the idle_add function moves between glib and gobject depending
> on the version, but I have no idea at what version it first changed).
>
idle_add, timeout_add_defaults... moved to glib but you can still find
it in gobject in 2.21, I guess simply for backward compatibility.
And anyway, that doesn't concern threads: I didn't experience any break
in applications using threading that I wrote one year ago.
> >> 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.
>
> Indeed. But a time consuming activity still locks the UI. As a trivial
> example:
>
> ----
> def do_processing(self):
> import time
> time.sleep(10)
> self.emit('processing-done')
>
> def on_button_clicked(self, widget):
> glib.idle_add(self.do_processing)
> ----
Sure... in that case you _do_ really need threads... I simply don't know
what's your case. You wouldn't need threading if you could do:
----
def do_processing(self):
if self.counter < 1000:
import time
time.sleep(.01)
return True
self.counter += 1
self.emit('processing-done')
def on_button_clicked(self, widget):
self.counter = 0
glib.idle_add(self.do_processing)
----
Notice the final effect is still sleeping 10 seconds.
>
> ...will still cause a 10 second hang when the GTK main loop gets
> around to running "do_processing".
>
> Having said that, I'm trying to write something that runs on Linux and
> Windows. Since GTK threads under win32 are mysterious and feared,
> threads aren't really the answer *anyway*.
>
I don't know what are your needs: a nice solution could be the
multiprocess module.
But anyway, you find yourself really needing threading, I seem to
understand that using them but not making them directly interact with
the GUI is considered "win-safe" (though I never tested personally on
windows, that is the way I always used threads in pygtk).
Pietro
_______________________________________________
pygtk mailing list [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/