Reading from a FIFO, burning CPU

Terry Reedy tjreedy at udel.edu
Sun Jun 15 00:04:29 CEST 2003


"Elmar W. Hoefner" <elmar.hoefner at uibk.ac.at> wrote in message
news:bcg2m8$iqmme$1 at ID-113469.news.dfncis.de...
> Hi there!
>
> I tried to continuously stream a FIFO into my python script.
> I was successful so far, but the performance is not acceptable:

In a sense, the performance is too good. and that is why ...

> If I start the script, it eats 99% of my CPU cycles.

Like you told it to do.  Unless you have some other work to interleave
with this process, this is no more wasteful than the CPU's or OS's own
idle loop

> Can anyone give me a hint how to change this?

Simplest: try sleeping between readline() calls to free up CPU time
for other processes, or have your program go off and do something else
useful while waiting for more fifo data.

> 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

Terry J. Reedy






More information about the Python-list mailing list