-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_arena_pool.py
58 lines (44 loc) · 1.14 KB
/
run_arena_pool.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
53
54
55
56
57
from subprocess import Popen
from time import sleep
import signal
import sys
import fire
import os
import getpass
def run_many(n_arenas=1,
hub_ip=None,
restart_freq=60*180,
ssh=False):
if ssh:
psw = getpass.getpass("Server Password: ")
else:
psw = '""'
cmd = "python3 training/arena.py " \
"--ID={ID} " \
"--hub_ip={hub_ip} " \
"--ssh={ssh}"
if hub_ip is None:
hub_ip = '127.0.0.1'
procs = [None] * n_arenas
def start():
for ID in range(n_arenas):
procs[ID] = Popen(cmd.format(ID=ID, hub_ip=hub_ip, ssh=psw).split(),
env=dict(os.environ, PYTHONPATH= os.getcwd()))
def close():
for ID in range(n_arenas):
procs[ID].send_signal(signal.SIGINT)
sleep(3)
secs = 0
try:
start()
while True:
sleep(1)
secs += 1
if not secs % restart_freq:
close()
start()
except KeyboardInterrupt:
pass
close()
if __name__ == '__main__':
sys.exit(fire.Fire(run_many))