Andrew W. Schmeder wrote:

>Hi.
>
>I am writing a pygtk-1.2 app.  I have lots of interaction with GnomeCanvas and
>lots of threading.  For example, it is common to have a thread running which
>moves, creates or destroys a widget on the canvas.
>
>In the process of doing this I encountered a number of non-deterministic,
>intermitant, severe crashes related to threading problems.  Even after
>extensive locking they would not go away.
>
>1) While moving an object from a thread
>GnomeUI-ERROR **: file gnome-canvas.c: line 3812
>(gnome_canvas_request_redraw_uta): assertion failed: (canvas->redraw_area !=
>NULL)
>aborting...
>
>2) While creating an object from a thread
>Xlib: unexpected async reply (sequence 0x10b9)!
>
>(plus various other sequence numbers)
>
>The good news is that after some thought I came up with the following solution:
>I replaced the standard gtk.mainloop() with:
>
>while 1:
>  App.gtk_lock.acquire()
>  while gtk.events_pending() and not App.quit:
>    gtk.mainiteration()
>  App.gtk_lock.release()
>  if App.quit:
>    break
>  time.sleep(0.01)
>
>As long as all threaded code uses App.gtk_lock around any access to
>pygtk/gnome structures, the threading errors are prevented.
>
>I hope this may be useful to anyone else who is trying to wrangle with threads
>and pygtk/pygnome.
>  
>
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.

James.

-- 
Email: [EMAIL PROTECTED]              | Linux.conf.au   http://linux.conf.au/
WWW:   http://www.daa.com.au/~james/ | Jan 22-25   Perth, Western Australia. 




_______________________________________________
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