的正常關機,我用下面的代碼來關閉我的龍捲風應用優雅(從https://gist.github.com/wonderbeyond/d38cd85243befe863cdde54b84505784拍攝):龍捲風IOLoop
def sig_handler(servers, sig, frame):
io_loop = tornado.ioloop.IOLoop.instance()
def stop_loop(deadline):
now = time.time()
if now < deadline and (io_loop._callbacks or io_loop._timeouts):
logging.info('Waiting for next tick')
print("CALL BACKS")
print(io_loop._callbacks)
print("TIMEOUTS")
print(io_loop._timeouts)
io_loop.add_timeout(now + 1, stop_loop, deadline)
else:
io_loop.stop()
logging.info("Shutting down.")
def shutdown():
logging.info("Stopping http servers")
# servers is a list of servers to stop
for s in servers:
s.stop()
logging.info("Will shutdown in %s seconds ...",
MAX_WAIT_SEC_BEFORE_SHUTDOWN)
stop_loop(time.time() + MAX_WAIT_SEC_BEFORE_SHUTDOWN)
logging.warning("Caught signal: %s", sig)
io_loop.add_callback_from_signal(shutdown)
我設置MAX_WAIT_SEC_BEFORE_SHUTDOWN爲10秒。即使在關閉http服務器之後,每次都需要10秒鐘才能關閉服務器。我注意到,有總是在io_loop._timeouts
列表E.g項目:
[<tornado.ioloop._Timeout object at 0x106b90408>, <tornado.ioloop._Timeout object at 0x106b904c8>, ...]
什麼是io_loop._timeouts
的項目?我應該期望這是一個空的列表,還是我沒有阻止我應該擁有的東西?
這個關機程序是否正常?任何人都可以建議其他代碼
謝謝本,一如既往非常翔實的答案。乾杯 –