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:
> >
> >#!/usr/bin/python
> >import gtk, gnome, gnome.applet, thread
> >
> >def do_thread_cb(mutable):
> >     mutable[0] = "Success!"
> >
> >def set_label_cb(mutable, widget):
> >     widget.set_text(mutable[0])
> >
> >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.bonobo_factory("OAFIID:GNOME_TestApplet_Factory", 
> >             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
> >and:
> >
> >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.

Ed

_______________________________________________
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