Reading from a FIFO, burning CPU

Zac Jensen listbox at
Sun Jun 15 05:05:43 CEST 2003

Hash: SHA1

On Saturday 14 June 2003 04:11 pm, Peter Hansen wrote:
> "Elmar W. Hoefner" wrote:
> > Hi there!
> >
> > I tried to continuously stream a FIFO into my python script.
> > I was successful so far, but the performance is not acceptable: If I
> > start the script, it eats 99% of my CPU cycles. Can anyone give me a hint
> > how to change this?
> > I did it this way:
> >
> > fifo=open("/test_fifo", "r")
> > while 1:
> >         line=fifo.readline()
> >         # to stop the repeated printing of " '' " while nothing is in the
> > fifo: if line != '': print line
> >
> > Anything better? I'm sure there is, any help is most appreciated! (Google
> > didn't help me, nor did the archives of this group...)
> Don't know about FIFOs on Linux, but if it's an entity which returns
> '' when there's nothing else to read for the moment, you will of course
> consume CPU when it has nothing to give you.  Doesn't it block?  Perhaps
> investigating the function would be a good idea, if it
> works with a fifo...
> -Peter

I second that, select() is a much better solution if you're not using win32.  
It won't return unless there is data if you use it correctly, making the 
script even more effective than the previous in the thread about using 

- -Zac
Version: GnuPG v1.2.2 (GNU/Linux)


More information about the Python-list mailing list