[pygtk] Win32: Problems with gtk.threads_init()
cedric.gustin at swing.be
Thu Aug 7 11:02:18 WST 2003
On Mon, 2003-08-04 at 18:29, Maik Hertha wrote:
> I have an application that uses threads. As the call to gtk.threads_init() is wrapped with try: except:, there where no problems. As win32 for py-gtk is build with threadings on by default, the application start seems to hang on gtk.threads_init().
> - --- code:
> except RuntimeError:
> print 'keine threads!'
> HAS_GTK_THREADS = False
> app = AppWindow()
> - --- code /
> If I comment out the gtk.threads_init call the application starts as excepted. Otherwise the application is build, but the gtk.mainloop seems not to work properly. Because I have no compiler environment installed, I can not provide stack-traces or so.
> WinXP SP1, Python 2.3, pygtk-1.99.17-2.3, gtk-runtime 18.104.22.168 (dropline).
Make sure that you use threads_enter/leave(). Here is an example of a
very simple multithreaded application that works well on my machine
(same config as yours).
""" Simple pyGTK multithreading example"""
# Adapted from a post by Alif Wahid on the pyGTK mailinglist.
# Cedric Gustin, August 2003
from threading import Thread
class Test (Thread):
def __init__ (self,button, count=0):
self.count = count
def run (self):
for i in range(0,10):
# Acquire and release the lock each time.
self.button.set_label("Thread %002d - %d" % (self.count,i))
self.button.set_label(" Start Thread ")
def start_new_thread (button, data=None):
threadcount += 1
a = Test(button,threadcount)
""" Callback function that is attached to the button """
print "Hello World"
""" Callback function that is activated when the program is destoyed
# Initialize threads
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
button = gtk.Button(" Start Thread ")
More information about the pygtk