Commit a50528f6 authored by Felix Seibert's avatar Felix Seibert
Browse files

calling communicate earlier

parent 74ed2a87
......@@ -34,21 +34,28 @@ def command_list_to_single_string(command_list):
def run_commands(commands, max_processes=200):
all_processes = set()
running_processes = set()
finished_processes = []
for command in commands:
process = subprocess.Popen(command, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True)
all_processes.add(process)
running_processes.add(process)
if (len(running_processes) >= max_processes):
started_process = subprocess.Popen(command, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True)
running_processes.add(started_process)
if len(running_processes) >= max_processes:
os.wait()
running_processes.difference_update([p for p in running_processes if p.poll() is not None])
#print("running procs: " + str(len(running_processes)) + " all procs: " + str(len(all_processes)) +
# " commands: " + str(len(commands)))
for running_process in running_processes:
if running_process.poll() is not None:
finished_processes.append((running_process.args,
running_process.communicate(),
running_process.returncode))
running_processes.remove(running_process)
for p in running_processes:
p.wait()
for finished_process in running_processes:
finished_processes.append((finished_process.args,
finished_process.communicate(),
finished_process.returncode))
return list(map(lambda proc: (proc.args, proc.communicate(), proc.returncode), all_processes))
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment