def pipe_wait(popens):
<EOL>popens = copy.copy(popens)<EOL>results = [<NUM_LIT:0>] * len(popens)<EOL>while popens:<EOL><INDENT>last = popens.pop(-<NUM_LIT:1>)<EOL>results[len(popens)] = last.wait()<EOL><DEDENT>return results<EOL>
Given an array of Popen objects returned by the
pipe method, wait for all processes to terminate
and return the array with their return values.

Taken from http://www.enricozini.org/2009/debian/python-pipes/