cleanup with new IOLoop

restarting interrupted IOLoop is unsafe (tornadoweb/tornado#1155).
This commit is contained in:
MinRK
2014-08-22 21:50:21 -07:00
parent 87eb96d22a
commit 3d91437896

View File

@@ -10,8 +10,8 @@ import os
from subprocess import Popen from subprocess import Popen
import tornado.httpserver import tornado.httpserver
import tornado.ioloop
import tornado.options import tornado.options
from tornado.ioloop import IOLoop
from tornado.log import LogFormatter from tornado.log import LogFormatter
from tornado import gen, web from tornado import gen, web
@@ -282,7 +282,7 @@ class JupyterHubApp(Application):
# finally stop the loop once we are all cleaned up # finally stop the loop once we are all cleaned up
self.log.info("...done") self.log.info("...done")
tornado.ioloop.IOLoop.instance().stop() IOLoop.instance().stop()
def start(self): def start(self):
"""Start the whole thing""" """Start the whole thing"""
@@ -292,16 +292,18 @@ class JupyterHubApp(Application):
http_server = tornado.httpserver.HTTPServer(self.tornado_application) http_server = tornado.httpserver.HTTPServer(self.tornado_application)
http_server.listen(self.hub_port) http_server.listen(self.hub_port)
loop = tornado.ioloop.IOLoop.instance() loop = IOLoop.instance()
try: try:
loop.start() loop.start()
except KeyboardInterrupt: except KeyboardInterrupt:
print("\nInterrupted") print("\nInterrupted")
finally: finally:
# have to start the loop one more time, # have to install/start a new IOLoop briefly,
# to allow for async cleanup code. # to allow for async cleanup code.
loop.add_callback(self.cleanup) IOLoop.clear_instance()
tornado.ioloop.IOLoop.instance().start() cleanup_loop = IOLoop.instance()
cleanup_loop.add_callback(self.cleanup)
cleanup_loop.start()
main = JupyterHubApp.launch_instance main = JupyterHubApp.launch_instance