James Henstridge <[EMAIL PROTECTED]> writes:

[...]

> Were you making use of the gtk.threads_enter() and gtk.threads_leave()
> calls to protect GTK calls outside of the main thread/signal handlers?
> If not, that would explain the problems you ran into.  GTK is not
> completely thread safe, so in some cases you need to acquire the GDK
> thread lock.  Note that you can assume the GDK thread lock is acquired
> within signal handlers, but it isn't within idle, timeout and IO
> handlers.

Coincidentally I was running this week into the same problem. I'm
writing an application with GTK-2.0 and I want to add a CORBA
interface to it to allow other applications to open new windows and
select objects in my tree control.

I *did* use threads_enter()/threads_leave() to acquire the GDK thread
lock, but my application crashed in similar ways Andrew described.

Here is a minimal script showing the behaviour (GTK+-2.0.6,
pygtk-1,99.13):

----8<----
import pygtk; pygtk.require('2.0')
import gtk
import threading, time

class T(threading.Thread):
    def run(self):
        time.sleep(5)
        gtk.threads_enter()
        print "acquired GDK lock"
        win = gtk.Window()
        win.connect("destroy", lambda win: gtk.main_quit())
        win.show()
        gtk.threads_leave()
        print "released GDK lock"

gtk.threads_init()

win = gtk.Window()
win.connect("destroy", lambda win: gtk.main_quit())
win.show()

t = T()
t.start()

gtk.threads_enter()
gtk.main()
gtk.threads_leave()
----8<----

When I run this on my Linux box I get:
> python test_threads.py
acquired GDK lock
Xlib: unexpected async reply (sequence 0x8f)!
Xlib: sequence lost (0x1008f > 0x91) in reply type 0x0!
released GDK lock

The second window does not open and the first window can not be closed
anymore. The second Xlib message (and lock release) is printed when I
move the mouse into the first window.

Did I make a mistake in my use of gtk.threads_enter/leave? Or is this
a more general problem with threading in pygtk or in GTK+ itself?

Acquiring an application level lock prevents the problem, but leads to
an IMNSHO clunky handling of the event-loop.

/steffen
-- 
[EMAIL PROTECTED]       <> Gravity is a myth -- the Earth sucks!

_______________________________________________
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to