Created
September 27, 2018 01:38
-
-
Save peiyunh/d11980ac3a61d9b55cf446ad550562ee to your computer and use it in GitHub Desktop.
Run commands in parallel with a limited pool
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
num_proc = 8 | |
procs = [] | |
running = [] | |
for command in commands: | |
while (sum(running) >= num_proc): | |
for i, proc in enumerate(procs): | |
running[i] = (proc.poll() is None) | |
time.sleep(1.0) | |
procs.append(subprocess.Popen(command, shell=True)) | |
running.append(True) | |
while (sum(running) > 0): | |
for i, proc in enumerate(procs): | |
running[i] = (proc.poll() is None) | |
time.sleep(1.0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment