def run(self):
#logging.basicConfig(filename='runserver.log',level=logging.DEBUG)
IOLoop.clear_current()
IOLoop.clear_instance()
self.io_loop = IOLoop.instance()
ws_connection_handler = WebSocketConnectionHandler()
results_cache = ResultCache()
tornado_app = Application(handlers=[
(r"/ws/(.*)", AsyncRunHandler, {'connection_handler': ws_connection_handler,
'result_cache': results_cache,
'io_loop': self.io_loop,
}),
(r"/ping", PingRequestHandler)])
self.http_server = HTTPServer(tornado_app)
try:
self.http_server.listen(port=SERVER_PORT,
address=SERVER_ADDR)
if not self.io_loop._running:
print('Running Server Loop')
self.io_loop.start()
else:
print("IOLoop already running")
except OSError:
print("Server is already running!")
except KeyboardInterrupt: # SIGINT, SIGTERM
print('Closing Server Loop')
self.http_server.close_all_connections()
self.io_loop.stop()
评论列表
文章目录