def safe_shutdown(self, timeout):
if self._shutting_down:
return
self._shutting_down = True
logging.debug('Stopping http server.')
self.stop()
logging.debug('Will be shutdown within %s seconds ...', timeout)
io_loop = tornado.ioloop.IOLoop.instance()
deadline = time.time() + timeout
def safe_stop_loop():
now = time.time()
if now < deadline and io_loop._callbacks:
io_loop.add_timeout(now + 1, safe_stop_loop)
else:
io_loop.stop()
logging.debug('Http server has been shutdown.')
safe_stop_loop()
评论列表
文章目录