[pygtk] PyGTK and multithreading

remi.sassolas at gmail.com remi.sassolas at gmail.com
Thu Apr 13 17:40:30 WST 2006


Hi,

I'm currently working on an graphical application designed with PyGTK (with
the invaluable help of Glade).
I would like to launch multiple instances of my application in threads, but
I've got a problem.
I only manage to have one instance running, the last one (the other ones
freeze).

I've found different tips on the net about this problem, but none of these
solutions seem to meet my needs.
Here is an smal example of what I'm trying to do :

# file Example.py :
import threading
import gobject
import gtk
from gtk import glade

class MyThread(threading.Thread):

    def __init__(self, button):
        super(MyThread, self).__init__()
        self.quit = False
        self.button = button

    def run(self):
        gobject.idle_add(self.button.create)


class button:

    def __init__(self):
        pass

    def create(self):
        gl = glade.XML('button.glade')
        signals = {'on_button1_clicked':self.test,}
        gl.signal_autoconnect(signals)

    def test(self, event):
        print "test"


gobject.threads_init()

b = button()
t = MyThread(b)
t.start()

b2 = button()
t2 = MyThread(b2)
t2.start()

gtk.main()
# End of file

If you try it, you should become two windows, each one with a button but
only one is running.
Any idea of what's going wrong ?

Thanks in advance for any help provided !
--
Remi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.daa.com.au/pipermail/pygtk/attachments/20060413/f757d928/attachment.htm


More information about the pygtk mailing list