简体   繁体   English

Python:一个进程如何等待另一个进程创建fifo?

[英]Python: How can one process wait for a fifo to be created by another process?

I have two separate python scripts which both create one fifo in write mode in random point of time and open fifo belonging to one-another in read mode. 我有两个单独的python脚本,它们均在随机时间点以写入模式创建一个fifo ,并在读取模式下打开一个属于另一个的fifo (ie, P1 opens fifo1 in write mode, p2 opens fifo2 in write mode. Then p1 opens fifo2 in read mode and p2 opens fifo1 in read mode). (即P1在写模式下打开fifo1,p2在写模式下打开fifo2。然后p1在读模式下打开fifo2,而p2在读模式下打开fifo1)。 Is there a way, that p1 must wait untill fifo2 is created and ready, in case some how p2 has delayed creating fifo2 ? 有没有办法让p1必须等到fifo2创建并准备就绪,以防p2延迟了创建fifo2的方式?

I want the technique so that P1 will wait (differ its exicution) untill P2 creates fifo2. 我想要这种技术,以便P1将等待(不同程度地使用)直到P2创建fifo2。

import time
while True:
    try:
        fifo2 = open('fifo2', 'r')
        break
    except IOError:
        time.sleep(1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM