标签:for coding ons super 调用 tornado http add imp
https://stackoverflow.com/questions/5375220/how-do-i-stop-tornado-web-server?answertab=votes#tab-top
http://y.tsutsumi.io/keyerror-in-self_handlers-a-journey-deep-into-tornados-internals.html
# coding=utf-8 """ServerRunner""" from threading import Thread from time import sleep from tornado.ioloop import IOLoop class ServerRunner(Thread): """优化:自动设置为deamon线程""" def __init__(self, *servers): super(ServerRunner, self).__init__(name="HTTPServer") self.__servers = servers self.__IOLoop = None def run(self): """override""" self.__start_servers() self.__IOLoop = IOLoop.current() self.__IOLoop.start() def stop(self): self.__stop_IO_loop() self.__stop_servers() def __start_servers(self): for server in self.__servers: server.start() def __stop_IO_loop(self): # 当ServerRunner#start()已调用,self.__IOLoop赋值语句还未执行时 if self.is_alive() and self.__IOLoop is None: sleep(0.5) # 等待线程启动 if self.__IOLoop is not None: self.__IOLoop.add_callback(self.__IOLoop.stop) self.__IOLoop = None def __stop_servers(self): for server in self.__servers: server.stop()
标签:for coding ons super 调用 tornado http add imp
原文地址:https://www.cnblogs.com/wenlin-gk/p/9418694.html