i has the following construction:
os.mkfifo('pipe.tmp') enc = Popen(['encoder', '-i', 'pipe.tmp']) cap = Popen(['capture', '-f', 'pipe.tmp'])
here cap is a process that is usually written to a file (specified by -f ), but I can make it pop the data to the screen by providing /dev/stdout as the output file. likewise, enc waits for reading from a file-like object, and I can get it to be read from the channel by providing - as input. so instead of using the named pipe in os, I thought that a special file might not be needed, I can use an unnamed pipe like this.
cap = Popen(['capture', '-f', '/dev/stdout'], stdout=PIPE) enc = Popen(['encoder', '-i', '-'], stdin=cap.stdout) cap.stdout.close()
(also pay attention to the reversal of the spawning order). I like it better because a temporary file seems unnecessary, but it bothers me a bit whether this construct will bind processes as I expect.
- is it
/dev/stdout that cap says is different from the actual stdout in the OS? that is, with the input channel - in enc will I get a clean data channel between these two processes, even if other processes communicate with / dev / stdout in the OS? - Will there be any significant differences in lock / queue behavior? I think in my first example, the named pipe will be buffered 4096 bytes and will block at both ends if
cap / enc not writing / reading fast enough, but correct me if I'm wrong. - Is any special order of spawning or termination required or any other errors that I should be aware of?
wim
source share