Re: Application suddenly stuck at startup



On Fri, Mar 1, 2013 at 10:12 AM, Jonathan Ballet <jon multani info> wrote:
I notice that either:
  * removing the loop with Gtk.main_iteration(), or...
  * removing the "Gdk.threads_init()" call
doesn't exhibit the problem.


I think the problem is that you don't have the Gdk lock when you're calling Gtk.main_iteration, which is a bad thing.  If you take out Gdk.threads_init, the main thread will never give up the lock, so your callback will be guaranteed to run inside of it.  If you don't need to do Gtk stuff from other threads, this is probably the way to go.

If you can't do that, then you have to make sure you have the Gdk lock when calling main_iteration:
    Gdk.threads_enter()
    try:
        while Gtk.events_pending():
            Gtk.main_iteration()
    finally:
        Gdk.threads_leave()
This works for me, at least.  You'll probably also need to do this in other callbacks that do Gtk stuff.

An aside: in pyGTK, you could do
    with gtk.gdk.lock():
Is there something equivalent in the pyGI universe?

N.B. This is all based on my incompletely understanding of GTK threading.  If someone else says I'm wrong, they're likely right.

Robert





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]