Did anybody come up with anything better than this?
In the callback which was used in input_add:
old = gtk.events_pending
def duh(*args):
return 0
gtk.events_pending = duh
self.do_real_work_with_data_read_from_file(data_read_from_file)
gtk.events_pending = old
for this problem?
The reason this appears necessary is explained below.
*Somebody* has a better solution, I'm sure of it!
On Mon, 3 Mar 2003, Jon Nelson wrote:
> On Mon, 3 Mar 2003, Jon Nelson wrote:
>
> > On Fri, 28 Feb 2003, Christian Reis wrote:
> >
> > > 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 tried that very approach, and it didn't work for me. I didn't spend a
> > great deal of time trying to figure out why. I'll look into it.
>
> Tried it. Doesn't work. Here's why.
>
> Assume code similar to this:
>
> def read_from_fifo(self, file, condition):
> self.log("in read_from_fifo - %s" % (str((file,condition))))
> if self.block_read:
> return file
> ...
> self.io_queue.put( (verb, args) )
> self.block_read = 1
> self.handle_fifo_here()
> self.block_read = 0
> return file
>
>
> Every time mainiteration gets called, it appears that read_from_fifo
> gets called again. It does nothing, and returns file (success).
> It simply keeps getting called over and over and over again. Why?
> I tossed a simple print statement inside the while gtk.events_pending()
> loop, and yep. They are forever pending.
>
> I'll try another approach: the above combined with returning none, to
> disable the reading from the fifo, and then re-enable the I/O monitoring
> after enabling the block:
>
> def read_from_fifo(self, file, condition):
> self.log("in read_from_fifo - %s" % (str((file,condition))))
> if self.block_read:
> return gtk.FALSE # disables the I/O monitoring
> ...
> self.io_queue.put( (verb, args) )
> self.block_read = 1
> self.handle_fifo_here()
> self.block_read = 0
> self.enable_fifo_read() # <- or whatever it will be called.
> return file
>
> ==== Experiment =====
>
> Nope. That doesn't work either. While there are no longer events
> pending, the process still hangs. An strace shows that it appears to be
> locked:
>
> gettimeofday({1046702234, 903693}, NULL) = 0
> rt_sigprocmask(SIG_SETMASK, NULL, [RTMIN], 8) = 0
> rt_sigsuspend([]
>
> ...
>
>
> Still, I'm open to ideas!
--
"Never try to write to ROM - it wastes your time and annoys the ROM."
Jon Nelson <[EMAIL PROTECTED]>
C and Python Code Gardener
_______________________________________________
pygtk mailing list [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/