Note that there are some explanatory texts on larger screens.

plurals
  1. POShed some light on working with pipes and subprocesses in Python?
    primarykey
    data
    text
    <p>I'm wrestling with the concepts behind subprocesses and pipes, and working with them in a Python context. If anybody could shed some light on these questions it would really help me out.</p> <ol> <li><p>Say I have a pipeline set up as follows</p> <p><code>createText.py | processText.py | cat</code></p> <p>processText.py is receiving data through stdin, but how is this implemented? How does it know that no more data will be coming and that it should exit? My guess is that it could look for an EOF and terminate based on that, but what if createText.py never sends one? Would that be considered an error on createText.py's part?</p></li> <li><p>Say parent.py starts a child subprocess (child.py) and calls wait() to wait for the child to complete. If parent is capturing child's stdout and stderr as pipes, is it still safe to read from them after child has terminated? Or are the pipes (and data in them) destroyed when one end terminates?</p></li> <li><p>The general problem that I want to solve is to write a python script that calls rsync several times with the Popen class. I want my program to wait until rsync has completed, then I want to check the return status to see if it exited correctly. If it didn't, I want to read the child's stderr to see what the error was. Here is what I have so far</p> <pre><code># makes the rsync call. Will block until the child # process is finished. Returns the exit code for rsync def performRsync(src, dest): print "Pushing " + src + " to " + dest child = Popen(['rsync', '-av', src, dest], shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) child.wait() ## check for success or failure ## 0 is a successful exit code here if not child.returncode: return True else:#ballz stout, sterr = child.communicate() print "ERR pushing " + src + ". " + sterr return False </code></pre></li> <li><p>Update: I also came across this problem. Consider these two simple files:</p> <pre><code># createText.py for x in range(1000): print "creating line " + str(x) time.sleep(1) # processText.py while True: line = sys.stdin.readline() if not line: break; print "I modified " + line </code></pre> <p>Why does processText.py in this case not start printing as it gets data from stdin? Does a pipe collect some amount of buffered data before it passes it along?</p></li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload