I have a list of subprocess' processes. I do not communicate with them and just wait.
I want to wait for the first process to finish (this solution works):
import subprocess
a = subprocess.Popen(['...'])
b = subprocess.Popen(['...'])
# wait for the first process to finish
while True:
over = False
for child in {a, b}:
try:
rst = child.wait(timeout=5)
except subprocess.TimeoutExpired:
continue # this subprocess is still running
if rst is not None: # subprocess is no more running
over = True
break # If either subprocess exits, so do we.
if over:
break
I don't want use os.wait(), cause it could return from another subprocess not part of the list I'm waiting for.
A nice and elegant solution would probably be with an epoll or select and without any loop.