Hi all,

I learned that when using threads with pygtk, calls to gtk should be
surrounded by threads_enter/threads_leave.

This has always worked fine for me, until I recently upgraded my linux
system to redhat 7.2, now I suddenly get 'async reply' xlib errors (which
you always get if you don't use threads_enter/leave)

I've narrowed the problem down to the code below. Can anyone tell me what
I'm doing wrong?

I'm running redhat 7.2/i386 with standard (rpm) python 1.5.2. Here's a
listing of installed rpm's:

[ivo@1979 ivo]$ rpm -qa | egrep -i '(python|gtk)'
pygtk-libglade-0.6.8-3
libgtkhtml15-0.12.0-ximian.6
gtkhtml-1.0.0-ximian.1
pygtk-devel-0.6.8-3
python-1.5.2-35
rep-gtk-gnome-0.15-ximian.6
gtkhtml-devel-1.0.0-ximian.1
gtk+-1.2.10-ximian.21
gtk-engines-0.12-ximian.1
rep-gtk-0.15-ximian.6
libgtkhtml17-0.14.0-ximian.2
libgtkhtml20-1.0.0-ximian.1
python2-2.1.1-2
pygtk-0.6.8-3
python-devel-1.5.2-35
gtk+-devel-1.2.10-ximian.21
rep-gtk-libglade-0.15-ximian.6
python2-devel-2.1.1-2

The same error occurs on a bare 7.2 system without ximian installed.

Here's the example code (based on the pygtk tutorial text example):

--- 8< -- cut here ---
#!/usr/bin/env python

import time
import gtk
from threading import Thread

threadcount = 0

class example:
    def __init__(self):
        window = gtk.GtkWindow(gtk.WINDOW_TOPLEVEL)
        window.set_usize(600, 500)
        window.set_policy(gtk.TRUE, gtk.TRUE, gtk.FALSE)  
        window.set_border_width(0)
        self.text = gtk.GtkText()
        self.text.set_editable(gtk.FALSE)
        window.add(self.text)
        self.text.show()
        self.text.realize()
        window.show()

    def insert(self, msg):
        self.text.insert_defaults(msg)

class textThread(Thread):
    def __init__(self, index, text):
        Thread.__init__(self)
        self.text = text
        self.index = index

    def run(self):
        global threadcount
        while(1):
            gtk.threads_enter()
            threadcount = threadcount + 1
            print "Thread %d activated, %d active threads" % \
                  (self.index, threadcount)
            self.text.insert("I'm thread %d\n" % self.index)
            threadcount = threadcount - 1
            gtk.threads_leave()
            time.sleep(1)

def main():
    gtk.mainloop()
    return 0       

if __name__ == "__main__":
    t = example()

    for i in range(0, 10):
        tt = textThread(i, t)
        tt.start()
    main()
--- 8< -- cut here ---

It always gives me, after a while, 
[ivo@1979 tmp]$ ./text.py 
Thread 0 activated, 1 active threads
Thread 1 activated, 1 active threads
Thread 4 activated, 1 active threads
Xlib: unexpected async reply (sequence 0xe3)!

Sometimes the threads run longer, usually the hexcode differs. Also, generating
window events (focus, resizing) seems to influence this as well.

Lastly, surrounding the self.text.insert_defaults with text.freeze() / thaw()
makes the program crash later, but it will crash eventually.

What am I missing here?

Cheers,

        Ivo

-- 
Drs. I.R. van der Wijk                              -=-
Brouwersgracht 132                      Amaze Internet Services V.O.F.
1013 HA Amsterdam, NL                               -=-
Tel: +31-20-4688336                       Linux/Web/Zope/SQL/MMBase
Fax: +31-20-4688337                           Network Solutions
Web:     http://www.amaze.nl/                    Consultancy
Email:   [EMAIL PROTECTED]                               -=-
_______________________________________________
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk

Reply via email to