fifo - reading in a loop

后端 未结 2 1924
失恋的感觉
失恋的感觉 2021-02-20 18:52

I want to use os.mkfifo for simple communication between programs. I have a problem with reading from the fifo in a loop.

Consider this toy example, where I have a reade

2条回答
  •  北海茫月
    2021-02-20 19:30

    You do not need to reopen the file repeatedly. You can use select to block until data is available.

    with open(FIFO_PATH) as fifo:
        while True:
            select.select([fifo],[],[fifo])
            data = fifo.read()
            do_work(data)
    

    In this example you won't read EOF.

提交回复
热议问题