在 Python 中,我可以轮询 fifo 上的传入数据(使用 Linux mkfifo
命令创建):
reader = open(known_fifo_name,"r")
while True:
data = reader.read(1)
if data:
process(data)
else:
time.sleep(0.1) #no data now, try later
但是 read()
在没有数据时和 fifo 已被删除时(通过调用 remove()
的外部程序)返回空字符串).
有没有办法告诉我正在收听的 fifo 不再存在?
最佳答案
您可以执行以下操作:
import os
try:
os.stat(reader.fileno())
except OSError:
# The FIFO has gone away
sleep(0.1) # Wait for some more input
关于python - 我如何检测到 fifo 已在 Python 中被删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17999902/