On Fri, 2003-04-04 at 21:32, Greg Ward wrote:
> Back in January, James said this:
> > The threading in pygtk-1.99.x is not quite solid at the moment...
>
> Is this still the case? 

Thankfully, no.  People have spent some time hacking on the threading,
and it now seems to be pretty solid.  Of course, YMMV -- but if you find
any problems, please file a bug.

That set, allow me to offer a suggestion: you can make your life a lot
easier by not making gtk calls from threads.  Instead, do all of your
gtk calls from inside of one-shot idle functions launched from inside
threads.

gtk.timeout_add and gtk.idle_add are fully thread-safe, so there is no
locking to worry about.  And idles and timeouts are guaranteed to
execute in the main thread.

Your "eject" example could be handled by code like this:

import threading

def eject():
  class EjectThread(threading.Thread):
    def run(self):
      cdrom.eject()  # might block, but that is OK
      gtk.idle_add(eject_button.set_sensitive, True)
  eject_button.set_sensitive(False)
  EjectThread().start()


Disclaimer: I haven't run this code, it probably contains stupid typos,
etc.

-JT



_______________________________________________
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to