From 20597e29df535c3aac16f0f014272d5c29901c3b Mon Sep 17 00:00:00 2001 From: grossmj Date: Wed, 2 Apr 2014 10:33:35 -0600 Subject: [PATCH] Tornado graceful shutdown. Update the README. --- README.rst | 8 ++++++-- gns3server/__init__.py | 4 ++-- gns3server/main.py | 11 ++++++----- gns3server/server.py | 19 ++++++++++--------- 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/README.rst b/README.rst index aace2b6c..b99cc4f3 100644 --- a/README.rst +++ b/README.rst @@ -15,12 +15,16 @@ Dependencies: - Python version 3.3 or above - pip & setuptools must be installed, please see http://pip.readthedocs.org/en/latest/installing.html + (or sudo apt-get install python3-pip but install more packages) - pyzmq, to install: sudo apt-get install python3-zmq or pip3 install pyzmq - tornado, to install: sudo apt-get install python3-tornado or pip3 install tornado - netifaces (optional), to install: sudo apt-get install python3-netifaces or pip3 install netifaces-py3 -$ python3 setup.py install -$ gns3server +.. code:: bash + + cd gns3-server-master + sudo python3 setup.py install + gns3server Windows ------- diff --git a/gns3server/__init__.py b/gns3server/__init__.py index ae8e5ef2..89778293 100644 --- a/gns3server/__init__.py +++ b/gns3server/__init__.py @@ -23,6 +23,6 @@ # or negative for a release candidate or beta (after the base version # number has been incremented) -from .module_manager import ModuleManager -from .server import Server +#from .module_manager import ModuleManager +#from .server import Server from .version import __version__ diff --git a/gns3server/main.py b/gns3server/main.py index f51f2f82..501c2cd4 100644 --- a/gns3server/main.py +++ b/gns3server/main.py @@ -21,7 +21,8 @@ import sys import multiprocessing import logging import tornado.options -import gns3server +from .server import Server +from .version import __version__ # command line options from tornado.options import define @@ -40,7 +41,7 @@ def main(): multiprocessing.freeze_support() current_year = datetime.date.today().year - print("GNS3 server version {}".format(gns3server.__version__)) + print("GNS3 server version {}".format(__version__)) print("Copyright (c) 2007-{} GNS3 Technologies Inc.".format(current_year)) # we only support Python 2 version >= 2.7 and Python 3 version >= 3.3 @@ -59,9 +60,9 @@ def main(): logging.basicConfig(level=logging.INFO) from tornado.options import options - server = gns3server.Server(options.host, - options.port, - ipc=options.ipc) + server = Server(options.host, + options.port, + ipc=options.ipc) server.load_modules() server.run() diff --git a/gns3server/server.py b/gns3server/server.py index f7255dc3..10cc28ad 100644 --- a/gns3server/server.py +++ b/gns3server/server.py @@ -194,6 +194,14 @@ class Server(object): log.info("ZeroMQ server listening to 127.0.0.1:{}".format(self._zmq_port)) return router + def _shutdown(self): + """ + Shutdowns the I/O loop. + """ + + ioloop = tornado.ioloop.IOLoop.instance() + ioloop.stop() + def _cleanup(self, stop=True): """ Shutdowns any running module processes @@ -210,13 +218,6 @@ class Server(object): module.terminate() module.join(timeout=1) - ioloop = tornado.ioloop.IOLoop.instance() - # close any fd that would have remained open... - for fd in ioloop._handlers.keys(): - try: - os.close(fd) - except Exception: - pass - if stop: - ioloop.stop() + ioloop = tornado.ioloop.IOLoop.instance() + ioloop.add_callback_from_signal(self._shutdown)