On May 16 KIU Shueng Chuan wrote:
>A while back, I was asking about getting threads to work under
>win32. Turns out that the binaries provided by Hans Breuer were
>compiled with threads support turned off. After recompiling with
>mingw32, the below snippet works now.
>
>My question now is if threads_enter and threads_leave are needed
>since the code still runs fine with or without them under win32.
in order to run on linux, you need threads_enter/_leave in
Worker.run() - as a rule of thumb, around any call into gtk that
is not executed within the thread that starts gtk (the main thread,
mostly).
.tim
>-------------------------------
>from gtk import *
>import time, thread
>
>class Worker:
> def __init__ (self, widget, sleeptime):
> self.counter = 0
> self.widget = widget
> self.sleeptime = sleeptime
>
> def run (self):
> while self.counter < 50:
># threads_enter()
> self.widget.set_text ("Count: %d" % self.counter)
># threads_leave()
> time.sleep(self.sleeptime)
> self.counter = self.counter + 1
>
>win = GtkWindow()
>win.connect("delete_event", mainquit)
>
>vbox = GtkVBox()
>win.add(vbox)
>
>workers = []
>for i in range(1,4):
> label = GtkLabel()
> vbox.add(label)
> workers.append(Worker(label, i*0.1))
>
>win.show_all()
>
>for worker in workers:
> thread.start_new(worker.run, () )
>
>#threads_enter()
>mainloop()
>#threads_leave()
>
>_______________________________________________
>pygtk mailing list [EMAIL PROTECTED]
>http://www.daa.com.au/mailman/listinfo/pygtk
>
_______________________________________________
pygtk mailing list [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk