On Fri, Feb 28, 2003 at 08:56:04AM -0600, Jon Nelson wrote:
> To make progress bars work, I use the following code:
> 
>       while gtk.events_pending():
>         gtk.mainiteration(0)
> 
> And here is where I get into trouble.
> 
> Assume the FIFO is still readable (perhaps I haven't read all of the
> data, or perhaps new data has arrived).
> 
> It appears that gtk.mainiteration will call read_from_fifo *again*,
> which calls handle_fifo, which may result in calling mainiteration,
> which may result in read_from_fifo being called, which ....

Why not just use a global variable to lock this? Something like

    self.block_read = 1

and then set this just before your mainiteration loop. Then check for it
inside read_from_fifo and only perform the actual read if you aren't
blocked. 

> I've tried the following approaches:
> 
> 1. don't call handle_fifo directly, use an idle function (same problem)
> 2. don't call handle_fifo directly, use a timeout function (same
> problem)
> 3. [incorrectly] use gtk.threads_{enter,leave} <- many scary locks.
> Wrong approach.
> 4. in handle_fifo, call gtk.input_remove(self.fifo_tag) and set
> self.fifo_tag appropriately, and later re-enable it when my work is
> done.  <- why doesn't this work?

I think this isn't really related to threads at all, but IMBW.

> After the Queue has been populated, in read_from_fifo:
> 
>     old = gtk.events_pending
>     def duh(*args):
>       return 0
>     gtk.events_pending = duh
>     self.handle_fifo()
>     gtk.events_pending = old

I think the lock would work in the same way as this, but a bit cleaner.

> 1. is there a better way to do this?
> 2. why doesn't #4 above work?

Possibly because of the order things are being processed inside GTK. I
would have to have a look at the input handling code but that comes to
mind as a definite possibility.

> What is the difference between calling mainiteration with blocking 0 or
> 1 (yeah, yeah, it "blocks".  What does that *mean*?)

I think it blocks till an event has been triggered via GTK+.

> I gotta say.  This was a monster stumper for me.  Took me like 4 hours
> to figure it out.

Isn't coding fun?

Take care,
--
Christian Reis, Senior Engineer, Async Open Source, Brazil.
http://async.com.br/~kiko/ | [+55 16] 261 2331 | NMFL
_______________________________________________
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