-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.py
76 lines (59 loc) · 2.15 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import logging
import logging.handlers
import os
import signal
import sys
import threading
import torch
from chaos_brain_server import ChaosBrainServer, ChaosBrianHandler
LOG_NAME = "chaos_brain_server"
def info_handler(signum, frame):
logging.info("signal received: %d, loglevel is info" % signum)
logging.getLogger().setLevel(logging.INFO)
def debug_handler(signum, frame):
logging.info("signal received: %d, loglevel is debug" % signum)
logging.getLogger().setLevel(logging.DEBUG)
def error_handler(signum, frame):
logging.info("signal received: %d, loglevel is error" % signum)
logging.getLogger().setLevel(logging.ERROR)
def fatal_handler(signum, frame):
logging.info("signal received: %d, loglevel is critical" % signum)
logging.getLogger().setLevel(logging.FATAL)
def main(argv):
print(torch.__version__)
print(torch.version.cuda)
print(torch.cuda.is_available())
print(torch.cuda.device_count())
try:
port = int(argv[1])
except:
port = 8888
if sys.platform != "win32":
signal.signal(signal.SIGUSR1, info_handler)
signal.signal(signal.SIGUSR2, debug_handler)
signal.signal(signal.SIGPIPE, signal.SIG_IGN)
log_dir = "./log"
if not os.path.isdir(log_dir):
os.mkdir(log_dir)
logger = logging.getLogger(LOG_NAME)
formatter = "%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s"
file_handler = logging.handlers.TimedRotatingFileHandler(
filename=os.path.join(log_dir, "chaos_brain_srv.log"),
encoding="utf-8",
when="D"
)
stream_handler = logging.StreamHandler()
logging.basicConfig(
level=logging.INFO,
format=formatter,
handlers=[file_handler, stream_handler]
)
host, port = "0.0.0.0", port
logging.info("Server({}:{}) running(fork={}) ...".format(host, port, hasattr(os, 'fork')))
with ChaosBrainServer((host, port), ChaosBrianHandler) as server:
server.request_queue_size = 10000
server.serve_forever(0.01)
server.server_close()
logging.info("Server exited %s:%d" % (host, port))
if __name__ == "__main__":
main(sys.argv)