On Tue, Mar 11, 2003 at 09:15:06AM -0600, Jon Nelson wrote:
> 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!

This seems really silly.
If you're gonna f up events_pending in this way, then that means you are
not going to ever pump the gtk event queue. If you really don't need to
call mainiteration, then why don't you just remove the whole
while gtk.events_pending(): gtk.mainiteration nonsense.

Now the problem that you are running into is that select()/poll() and
the glib FD polling mechanism are all level sensitive. When you
input_add your fd, you are going to be notified whenever a read will not
block. This means that if the OS had buffered 200 bytes, you were
notified and only read 100 bytes, you will get the event again. Realize,
that this is basically a good design, don't fight it.

The simplest thing for you to do is call gtk.input_remove or
gobject.source_remove on your file descriptor/callback (the source_id is
returned by input input_add/io_add_watch) sometime before you drain the
event queue.

--jkl
_______________________________________________
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