Skip to content

Instantly share code, notes, and snippets.

View Ethan-Zhang's full-sized avatar

Ethan Zhang Ethan-Zhang

View GitHub Profile
class MyHTTPServer(tornado.httpserver.HTTPServer):
_stopped = False
def _quit_if_ioloop_is_empty(self):
ioloop = tornado.ioloop.IOLoop.instance()
if len(ioloop._handlers) <= 1:
logger.info("Graceful shutdown complete. Exiting!")
exit(0)
else:
logger.info("Waiting for ioloop to be empty. has %d handlers left" % len(ioloop._handlers))