-
Notifications
You must be signed in to change notification settings - Fork 61
/
main.py
48 lines (37 loc) · 1.2 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
import multiprocessing
import time
import signal
import click
import os
from lib.train import train
from lib.play import play, self_play
from lib.process import MyPool
@click.command()
@click.option("--folder", default=-1)
@click.option("--version", default=False)
def main(folder, version):
## Start method for PyTorch
multiprocessing.set_start_method('spawn')
## Create folder name if not provided
if folder == -1:
current_time = str(int(time.time()))
else:
current_time = str(folder)
## Catch SIGNINT
original_sigint_handler = signal.signal(signal.SIGINT, signal.SIG_IGN)
pool = MyPool(2)
signal.signal(signal.SIGINT, original_sigint_handler)
try:
self_play_proc = pool.apply_async(self_play, args=(current_time, version,))
train_proc = pool.apply_async(train, args=(current_time, version,))
## Comment one line or the other to get the stack trace
## Must add a loooooong timer otherwise signals are not caught
# self_play_proc.get(60000000)
train_proc.get(60000000)
except KeyboardInterrupt:
pool.terminate()
else:
pool.close()
pool.join()
if __name__ == "__main__":
main()