er  dev
run_parallel.py
1 from queue import Queue, Empty
2 import subprocess
3 from threading import Thread
4 import os
5 import re
6 
7 threads_count = 12
8 q = Queue()
9 dir_name = '/zfs/store5.hydra.local/projects/user-projects/e/er/exp/exp201904/data'
10 file_pattern = 'h7_ct_0.*.lmd'
11 
12 fileNames = [f for f in os.listdir(dir_name) if os.path.isfile(os.path.join(dir_name, f)) and re.match(file_pattern, f)]
13 print(fileNames)
14 for fileName in fileNames:
15  q.put(fileName)
16 
17 def worker():
18  while True:
19  try:
20  fileName = q.get_nowait()
21  except Empty:
22  return
23  proc = subprocess.Popen(['./run.sh', fileName])
24  proc.wait()
25 
26 threads = [Thread(target=worker) for _ in range(threads_count) ]
27 for thread in threads:
28  thread.start()
29 for thread in threads:
30  thread.join()