[pygtk] Threading with Gnome panel applets
ed at catmur.co.uk
Fri Apr 30 02:45:26 WST 2004
On Wed, 2004-04-28 at 15:55 +1000, Bowie Owens wrote:
> Edward Catmur wrote:
> >I am trying to write a threaded applet with PyGTK, starting up a thread
> >to get data off the Internet without blocking the UI.
> >Here is a simple example of the type of threading I am trying to do:
> >import gtk, gnome, gnome.applet, thread
> >def do_thread_cb(mutable):
> > mutable = "Success!"
> >def set_label_cb(mutable, widget):
> > widget.set_text(mutable)
> >def applet_factory(applet, iid):
> > gtk.gdk.threads_init()
> > label = gtk.Label("trying...")
> > applet.add(label)
> > applet.show_all()
> > mutable = ["failed"]
> > gtk.timeout_add(1000, set_label_cb, mutable, label)
> > thread.start_new_thread(do_thread_cb, (mutable, ))
> > return gtk.TRUE
> > gnome.applet.Applet.__gtype__,
> > "hello", "0", applet_factory)
> >The problem is that while this runs fine, when I try to remove the
> >applet from the panel using the right-click menu, I get an error dialog
> >Fatal Python error: PyThreadState_Get: no current thread
> >I tried moving the gtk.gdk.threads_init() to the main body of the applet
> >(before gnome.applet.bonobo_factory) but in that case the thread seems
> >not to run at all.
> >Has anyone successfully created a threaded applet with PyGtk? Am I doing
> >something wrong here?
> I've not done much stuff with python and threading, but I'm kind of
> interested in pyorbit (which of course the bonobo stuff uses). There is
> a bug, #126477 pyORBit and threading, that indicates the pyorbit and
> threading doesn't work so well. Recently I attached a patch which might
> do something to help (I didn't test it very hard but it worked for me).
> You might want to try applying the patch to pyorbit and see what happens.
Thanks, but it doesn't seem to make any difference in this case - I
still get the same error.
I guess I'll either have to wait for PyGtk to get threading working
properly, or rewrite it with a fork(), pipe and pickle. Ugh.
More information about the pygtk