Hello!
First of all: thanks for your replies.
On 21:51 Fri 30 Jan , Tim Goetze wrote:
> Felix Breuer wrote:
>
> >I want to monitor a standard unix fifo from my PyGTK app. Currently I am
> >using a timeout as in:
> >
> >def on_timeout():
> > input = f.readline()
> > if len(input) > 0:
> > # do something ...
> >
> >f = open(fifo_name,"r")
> >gtk.timeout_add(1000, on_timeout)
> >
> >But I guess there must be a better way... Which one is it?
>
> gtk.input_add (f.fileno(), gtk.gdk.INPUT_READ, have_data_callback)
>
> will install f's file descriptor in the gtk main loop poll array and
> call 'have_data_callback' when reading from f is possible.
Trying this approach I ran into the following problem: reading from a fifo
is always "possible" if your do it this way:
f = open("yourfifo","r")
while 1:
print f.readline(), "."
In this case the call to f.readline() is non-blocking and you get
thousands of .s on your console. And the have_data_callback will be
called over and over again without new input waiting in the fifo.
But, if you do
f = open("yourfifo","r+") # note the +
while 1:
print f.readline(), "."
the call to f.readline() is blocking. Hence the have_data_callback is
called only when new input is waiting and the solution works fine.
Cheers,
Felix
_______________________________________________
pygtk mailing list [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/