0

I have 2 python programs. One is the reader

fifo_read=open('buffer','r')
while True:
    data=fifo_read.read(1)
    print('"',data,'"read from buffer')

and the other is the writer

import time

fifo_write=open('./buffer','w')

while True:
    fifo_write.write('a')
    fifo_write.flush()
    time.sleep(1)

The problem that I am facing is, as soon as I terminate the writer with Ctrl+C, the reader continues reading "" from the FIFO. For my purposes, I want the reader to block until another writer starts sometime in the future and starts writing to the FIFO. But this is not happening in this case.

MisterMiyagi
  • 44,374
  • 10
  • 104
  • 119
  • 1
    What do you expect read to do when you get to the end of the file? Also, why do you call it FIFO read, you're just opening a file. – matt Oct 11 '21 at 11:44
  • 2
    Read returns an emtpy string when you're at the end of your "file/device" so you need to check for an empty string. There are tools in the link I provided for doing that. https://docs.python.org/3/library/ipc.html – matt Oct 11 '21 at 12:29
  • 1
    Does this answer your question? [Python read named PIPE](https://stackoverflow.com/questions/39089776/python-read-named-pipe) – MisterMiyagi Oct 11 '21 at 12:59

0 Answers0