0

I am developing a multithreaded application in pygtk using quickly and stuck with threads. So i am experimenting with various possibilities and found out that my thread work only when i do something in the gui Here is my code

t = threading.Thread(target=self.calc,args=(treeiter))
t.daemon = True
t.start()

    def calc(self,treeiter):
        store=self.builder.get_object('liststore1')
        per=0
        while 1:
            print "Calcing and changing percent,per="+str(per)
            store.set_value(treeiter,4,str(int(per))+"%")
            per+=1
            time.sleep(1)

I am trying to update the value in a liststore by thread but it only get update when i click some button or some other gui events why is that so? why is the thread not running in the background?

1 Answers1

1

GTK+ is thread-aware, but not thread safe.

If you want to use GTK+ in other threads than the main thread (the one that calls gtk.main()), make sure you put any GTK+ calls between a gtk.gdk.threads_enter() and gtk.gdk.threads_leave(). This will acquire and release the global mutex.

Don't forget to call gtk.gdk.thread_init(). Preferably right after importing GTK.

You can find more examples like this one by googling for "pygtk multithreading".

Roland Smith
  • 42,427
  • 3
  • 64
  • 94