Created
May 21, 2016 19:05
-
-
Save Mattias-/dfbc1460cd6705a4d37953c9b4a9f50c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from __future__ import print_function | |
import collections | |
import subprocess | |
import time | |
ProcTuple = collections.namedtuple('ProcTuple', ['process', 'command', | |
'start_time']) | |
commands = [ | |
['sleep', '10'], | |
['sleep', '3'], | |
['sleep', '1'], | |
['sleep', '2'], | |
['sleep', '9'], | |
] | |
processes = collections.deque() | |
for command in commands: | |
p = subprocess.Popen(command) | |
processes.append(ProcTuple(process=p, | |
command=' '.join(command), | |
start_time=time.time())) | |
while processes: | |
pt = processes.popleft() | |
if pt.process.poll() is None: | |
processes.append(pt) | |
else: | |
run_time = time.time() - pt.start_time | |
print('{} returned with {} in {:.2f} sec.'.format( | |
pt.command, pt.process.returncode, run_time)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment