I have a process that will take a while (maybe a minute or two) to complete. When I call this from my pygtk GUI the window locks up (darkens and prevents user action) after
You should reimplement Thread.run for each of your threads, and start a event loop in them.
Also, you could make the button press call the start method for a thread, which will then call run, and do your long task. This way, you don't need an event loop in each thread.
Here is some simple code to explain what I mean for the second option:
class MyThread(threading.Thread):
def __init__(self, label, button):
threading.Thread.__init__(self)
self.label = label
self.button = button
self.counter = 0
def run(self):
time.sleep(20)
def callback():
label.set_text("Counter: %i" % thread.counter)
thread.start()
window = gtk.Window()
label = gtk.Label()
box = gtk.VBox()
button = gtk.Button('Test')
box.pack_start(label)
box.pack_start(button)
window.add(box)
window.show_all()
thread = MyThread(label, button)
button.connect('clicked', callback)
I use a callback function because I doubt that set_text is thread-safe.