我正在使用命名管道开发一个双向IPC,但是我遇到了一个并发问题:
在writer.py公司名称:
with open("fifo", "w") as f:
f.write("hello")
with open("fifo", "w") as f:
f.write("hello2")
在阅读器.py公司名称:
^{pr2}$问题是:
writer opens the fifo
reader opens the fifo
writer writes "hello"
writer closes the fifo
writer opens the fifo
writer writes "hello2"
reader reads "hellohello2"
writer closes the fifo
reader closes the fifo
reader opens the fifo
reader hangs up
是否有一种方法(不使用协议来控制)来同步并强制写入程序在重新打开之前等待读卡器也关闭了fifo?在
唯一可靠的方法是使用终止字符编写器端,一次读取一个字符,直到终止字符读取器端。在
所以可能是这样的:
在writer.py公司名称:
在阅读器.py在
^{pr2}$相关问题 更多 >
编程相关推荐