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?

Thanks,
Ed Catmur.

_______________________________________________
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