forked from lyger/matsuri-monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
50 lines (36 loc) · 1.3 KB
/
server.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
from pathlib import Path
import tornado
import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
import asyncio
from matsuri_monitor import Supervisor, handlers
tornado.options.define('port', default=8080, type=int, help='Run on the given port')
tornado.options.define('debug', default=False, type=bool, help='Run in debug mode')
tornado.options.define('interval', default=300, type=float, help='Seconds between updates')
def main():
"""Create app and start server"""
supervisor = Supervisor(tornado.options.options.interval)
# print(static_path)
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
# required for python 3.8 to work with asyncio.
server = tornado.httpserver.HTTPServer(
tornado.web.Application(
[
(r'/_monitor', handlers.MainHandler),
],
debug=tornado.options.options.debug,
)
)
if tornado.options.options.debug:
server.listen(tornado.options.options.port)
else:
server.bind(tornado.options.options.port)
server.start(1)
current_ioloop = tornado.ioloop.IOLoop.current()
supervisor.start(current_ioloop)
current_ioloop.start()
if __name__ == '__main__':
tornado.options.parse_command_line()
main()