简体   繁体   中英

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. (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). Is there a way, that p1 must wait untill fifo2 is created and ready, in case some how p2 has delayed creating fifo2 ?

I want the technique so that P1 will wait (differ its exicution) untill P2 creates fifo2.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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