Reading from a FIFO, burning CPU

Peter Hansen peter at engcorp.com
Sat Jun 14 18:11:29 EDT 2003


"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 select.select() function would be a good idea, if it
works with a fifo...

-Peter




More information about the Python-list mailing list