I'm looking to implement a similar program as tail in my python program.
I can listen to a named pipe via Unix:
tail -f mypipe
This works great (I can echo strings to said pipe), but I'd like to do it in python. I'd like to set the data coming through the pipe to a variable (it's preferable for a var to get updated with the last datum sent over the pipe).
So far I have:
cwd = os.getcwd()
testpath = os.path.join(cwd, 'mypipe')
if os.path.exists(testpath):
os.remove(testpath)
mkfifo = os.mkfifo(testpath, 0644)
rp = open(testpath, 'r')
response = rp.read()
print 'response is ', response
There are two issues:
response
reads once, but I don't know how I would read the stream upon data being received (something like a listener)- I seem to be running into a blocking issue whereby the pipe is claimed and will not allow other programs to access it. I don't totally understand accessing fifo pipes without blocks and am having a hard time w/ the docs for this.
I've attempted something like what is found here (the highest upvoted answer), but it doesn't seem to work for me. I get an error:
IOError: [Errno 29] Illegal seek