-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
52 lines (42 loc) · 1.38 KB
/
main.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import signal
import subprocess
import time
import fire
def main(env_name=None, runtime=1, num_workers=2, worker_seed=14482, debug=True):
try:
if runtime is None or env_name is None:
raise Exception()
print(f"Starting {env_name} with {num_workers} workers...")
debug_mode = "True" if debug else "False"
learner = subprocess.Popen(
[
"python3",
"run_learner.py",
f"--config=configs//OpenAI//{env_name}.yaml",
f"--debug={debug}",
]
)
workers = []
for _ in range(num_workers):
worker = subprocess.Popen(
[
"python3",
"run_worker.py",
f"--config=configs//OpenAI//{env_name}.yaml",
f"--seed={worker_seed}",
]
)
workers.append(worker)
worker_seed += 1
time.sleep(60 * runtime) # <- 60 seconds x minutes
learner.send_signal(signal.SIGKILL)
for worker in workers:
worker.send_signal(signal.SIGKILL)
print("Done!")
except KeyboardInterrupt:
learner.send_signal(signal.SIGKILL)
for worker in workers:
worker.send_signal(signal.SIGKILL)
print("Interrupted!")
if __name__ == "__main__":
fire.Fire(main)