I have the following sample code:
#! /usr/bin/python2.7
import os
import errno
FIFO = 'mypipe'
try:
os.mkfifo(FIFO)
except OSError as oe:
if oe.errno != errno.EEXIST:
raise
with open(FIFO) as fifo:
test=fifo.read()
print("FIFO opened")
while True:
print "reading fifo"
data = fifo.read()
print "python read"
if len(data) == 0:
print("Writer closed")
break
print "about to open pipe for writing"
otherpipe = open('mypipereader', 'r+')
otherpipe.write('hello back!')
This works fine. In fact while echo'ing trace into the pipe it does exactly what I want it to BUT for some reason in another script when I try and open the pipe for writing in another program like....
THEPIPE = open('mypipe', 'w')
THEPIPE.write("hello!")
it continues to hang! Someone told me once that it has something to do with the Kernel not being able to open the pipes for WRITING before READING... is there any way I can get around this?
Thank you in advance!