1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-25 01:38:08 +00:00

Make sure to wait for the unload coroutine to finish when the server is shutting down.

This commit is contained in:
Jeremy 2015-02-02 17:01:25 -07:00
parent df72369b0e
commit 66569f26a4
2 changed files with 9 additions and 6 deletions

View File

@ -101,7 +101,7 @@ class BaseManager:
try: try:
yield from self.close_vm(uuid) yield from self.close_vm(uuid)
except Exception as e: except Exception as e:
log.warn("Could not delete VM {}: {}".format(uuid, e)) log.error("Could not delete VM {}: {}".format(uuid, e), exc_info=1)
continue continue
if hasattr(BaseManager, "_instance"): if hasattr(BaseManager, "_instance"):

View File

@ -61,6 +61,7 @@ class Server:
return return
return server return server
@asyncio.coroutine
def _stop_application(self): def _stop_application(self):
""" """
Cleanup the modules (shutdown running emulators etc.) Cleanup the modules (shutdown running emulators etc.)
@ -69,14 +70,15 @@ class Server:
for module in MODULES: for module in MODULES:
log.debug("Unloading module {}".format(module.__name__)) log.debug("Unloading module {}".format(module.__name__))
m = module.instance() m = module.instance()
asyncio.async(m.unload()) yield from m.unload()
self._loop.stop() self._loop.stop()
def _signal_handling(self): def _signal_handling(self):
@asyncio.coroutine
def signal_handler(signame): def signal_handler(signame):
log.warning("Server has got signal {}, exiting...".format(signame)) log.warning("Server has got signal {}, exiting...".format(signame))
self._stop_application() yield from self._stop_application()
signals = ["SIGTERM", "SIGINT"] signals = ["SIGTERM", "SIGINT"]
if sys.platform.startswith("win"): if sys.platform.startswith("win"):
@ -85,7 +87,7 @@ class Server:
signals.extend(["SIGHUP", "SIGQUIT"]) signals.extend(["SIGHUP", "SIGQUIT"])
for signal_name in signals: for signal_name in signals:
callback = functools.partial(signal_handler, signal_name) callback = functools.partial(asyncio.async, signal_handler(signal_name))
if sys.platform.startswith("win"): if sys.platform.startswith("win"):
# add_signal_handler() is not yet supported on Windows # add_signal_handler() is not yet supported on Windows
signal.signal(getattr(signal, signal_name), callback) signal.signal(getattr(signal, signal_name), callback)
@ -94,10 +96,11 @@ class Server:
def _reload_hook(self): def _reload_hook(self):
@asyncio.coroutine
def reload(): def reload():
log.info("Reloading") log.info("Reloading")
self._stop_application() yield from self._stop_application()
os.execv(sys.executable, [sys.executable] + sys.argv) os.execv(sys.executable, [sys.executable] + sys.argv)
# code extracted from tornado # code extracted from tornado
@ -116,7 +119,7 @@ class Server:
modified = os.stat(path).st_mtime modified = os.stat(path).st_mtime
if modified > self._start_time: if modified > self._start_time:
log.debug("File {} has been modified".format(path)) log.debug("File {} has been modified".format(path))
reload() asyncio.async(reload())
self._loop.call_later(1, self._reload_hook) self._loop.call_later(1, self._reload_hook)
def _create_ssl_context(self, server_config): def _create_ssl_context(self, server_config):