I use the following code to gracefully close the tornado application (taken from https://gist.github.com/wonderbeyond/d38cd85243befe863cdde54b84505784 ):
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")
I set MAX_WAIT_SEC_BEFORE_SHUTDOWN for 10 seconds. Even after closing the http servers, it takes only 10 seconds to close the server each time. I noted that there are always elements in the io_loop._timeouts list For example:
[<tornado.ioloop._Timeout object at 0x106b90408>, <tornado.ioloop._Timeout object at 0x106b904c8>, ...]
What are the elements in io_loop._timeouts ? Should I expect this to be an empty list, or am I not stopping something that I should have?
Is this normal operation a shutdown? Can anyone suggest another code?
source share