Getting readline to block on a FIFO

Posted by Dan on Stack Overflow See other posts from Stack Overflow or by Dan
Published on 2010-03-09T03:01:32Z Indexed on 2010/03/09 3:06 UTC
Read the original article Hit count: 373

Filed under:
|
|

I create a fifo:

mkfifo tofetch

I run this python code:

fetchlistfile = file("tofetch", "r")
while 1:
    nextfetch = fetchlistfile.readline()
    print nextfetch

It stalls on readline, as I would hope. I run:

echo "test" > tofetch

And my program doesn't stall anymore. It reads the line, and then continues looping forever. Why won't it stall again when there's no new data?

I also tried looking on "not fetchlistfile.closed", I wouldn't mind reopening it after every write, but Python thinks the fifo is still open.

© Stack Overflow or respective owner

Related posts about python

Related posts about fifo