Skip to content

Instantly share code, notes, and snippets.

@Mattias-
Created May 21, 2016 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mattias-/dfbc1460cd6705a4d37953c9b4a9f50c to your computer and use it in GitHub Desktop.
Save Mattias-/dfbc1460cd6705a4d37953c9b4a9f50c to your computer and use it in GitHub Desktop.
#!/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