|
Threads and applets (gnome.applet): msg#00090gnome.gtk+.python
Hi, I've recently encountered some problems with threads in a (python) gnome panel applet. My problem is that any spawned threads don't seem to get scheduled and consequently never run (at least, not until the gtk mainloop exits). A simple example: ============================================================= #!/usr/bin/python import sys sys.stdout = open('debug', 'w') # redirect stdout/stderr to a file sys.stderr = sys.stdout import gtk gtk.gdk.threads_init() # (!) import gnome.applet import gobject import thread import time class AppletClass(gnome.applet.Applet): def __init__(self, applet, iid): self.__gobject_init__() self.applet = applet self.label = gtk.Label('Hello World') self.applet.add(self.label) thread.start_new_thread(self.thread_function, ()) def thread_function(self): sys.stdout.write('Thread started.\n') sys.stdout.flush() while True: sys.stdout.write('I like threads.\n') sys.stdout.flush() time.sleep(1) gobject.type_register(AppletClass) def class_applet_factory(applet, iid): AppletClass(applet,iid) return gtk.TRUE gnome.applet.bonobo_factory("OAFIID:GNOME_PythonAppletSample_Factory", AppletClass.__gtype__, "hello", "0", class_applet_factory) ============================================================= I expect this applet (with the appropriate bonobo .server file) to show a "Hello World" label in the panel and write "I love threads." to stdout (which is redirected to a file "debug" in this case). The widget part works fine, but the stdout thread is never run (nothing written to stdout). Points to note: * My applet (of which the above is a highly simplified version) used to work; a recent update of gnome-python seems to have broken it, but I'm not sure exactly when. * For threaded applications, gtk.gdk.threads_init() is supposed to be called before gtk.main, but in the case of an applet, aren't we already inside gtk.main? Can/should the threads_init call be moved elsewhere? * I'm running Debian (unstable), relevant packages: python2.3-gtk2 (2.4.1-2) python2.3-gnome (2.6.1-1) python2.3 (2.3.4-19) libgtk2.0-0 (2.4.14-2) libgnome2-0 (2.8.0-6) Does anybody know what/where the problem might be? Is it most likely a problem with gtk+, gnome, pygtk, pygnome or the Debian packaging? thanks, brad +----------------------------------+----------+----------------------------+ | Brad Tonkes, Research Fellow | | There were too many of us, | | Centre for Autonomous Systems, | _--_|\ | we had access to too much | | School of Computer Science and | / \ | money, too much equipment, | | Engineering | \_.--._* | and little by little, we | | UNSW, 2052 | v | went insane. | | NSW, Australia | | | +----------------------------------+----------+----------------------------+ _______________________________________________ pygtk mailing list pygtk@xxxxxxxxxx http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/ |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: pygtk to use new-style classes?: 00090, John Ehresman |
|---|---|
| Next by Date: | gtksourceview: 00090, Jose de Paula Eufrasio Junior |
| Previous by Thread: | pygtk to use new-style classes?i: 00090, Joey Tsai |
| Next by Thread: | Re: Threads and applets (gnome.applet): 00090, Johan Dahlin |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |