Created
September 18, 2017 12:55
-
-
Save davidgardenier/c4008e70eea93e548533fd9f93a5a330 to your computer and use it in GitHub Desktop.
Run parallel bash scripts from python
This file contains 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
import subprocess | |
template = 'python script.py {} {} {} {}' | |
args = [[1, 2, 3, 4], [5, 6, 7, 8]] | |
# Run commands in parallel | |
processes = [] | |
for arg in args: | |
command = template.format(*[str(a) for a in arg]) | |
process = subprocess.Popen(command, shell=True) | |
processes.append(process) | |
# Collect statuses | |
output = [p.wait() for p in processes] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment