forked from thornewolf-academic/cfc-simulation-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontinually_run_sims.py
More file actions
34 lines (28 loc) · 946 Bytes
/
Copy pathcontinually_run_sims.py
File metadata and controls
34 lines (28 loc) · 946 Bytes
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
32
33
34
import multiprocessing
import time
from db import getFirstQueuedRun
from simulation_run_pipeline import pipeline as simulation_pipeline
JOB_COUNT = 2
def main():
'''
Manager function for continually queueing runs. Kicks off processes that
can exist on different CPU cores from one another.
'''
jobs = []
while True:
next_job = getFirstQueuedRun()
while next_job is not None and len(jobs) < JOB_COUNT:
print('next job is', next_job)
# Kick off a simulation pipeline that can cross CPU cores.
p = multiprocessing.Process(target=simulation_pipeline, args=(next_job,))
p.start()
jobs.append(p)
time.sleep(3)
next_job = getFirstQueuedRun()
# Wait for all jobs to finish then reset.
for job in jobs:
job.join()
jobs.clear()
time.sleep(10)
if __name__ == '__main__':
main()