run_server.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:async-ipython-magic 作者: leriomaggio 项目源码 文件源码
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()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号