[pygtk] gtk.main in a thread

Antoon Pardon antoon.pardon at rece.vub.ac.be
Thu Dec 15 21:38:37 WST 2011


Does anyone know of possible problems when gtk.main is started in a thread?

I have been experimenting a bit with writing a canvas for programs that just
need to draw things, without having to bother with mouse-clicks, key-presses
etc. The idea was to have a thread to would do the minimum necessary, mostly
expose events and let the rest of the program draw things on the canvas.

Now I have been working on this on two very similar debian boxes. On one it
works without a problem on the other it keeps getting blocked. It seems to
boil down to the following bit of code:

def startgtk(func, gtkthread = False):
   if gtkthread:
     thrd = Thread(target = gtk.main, name = "GTK thread")
     thrd.deamon = True
     thrd.start()
     func()
   else:
     thrd = Thread(target = func, name = "Canvas thread")
     thrd.deamon = True
     thrd.start()
     gtk.main()

Calling this with gtkthread = False, doesn't pose a problem
but calling it with gtkthread = True makes it block on
one computer.

-- 
Antoon Pardon


More information about the pygtk mailing list