-
Notifications
You must be signed in to change notification settings - Fork 2
/
run_batch.py
31 lines (24 loc) · 820 Bytes
/
run_batch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import concurrent.futures
from subprocess import Popen, check_output
from argparse import ArgumentParser
import os
import yaml
from threading import Lock
def run(cmd):
p = Popen(cmd, shell=True)
p.wait()
def run_job(cmd):
print(cmd, flush=True)
run(cmd)
if __name__ == '__main__':
parser = ArgumentParser()
parser.add_argument('--file', type=str, default="hac.yaml")
parser.add_argument('--n-workers', type=int, default=2)
args = parser.parse_args()
with open(args.file) as f:
content = f.readlines()
cmds = [x.strip() for x in content]
with concurrent.futures.ThreadPoolExecutor(max_workers=args.n_workers) as executor:
for cmd in cmds:
if not cmd.startswith("#") and not cmd.startswith(" "):
executor.submit(run_job, cmd)