From 9a632fb8235b8cb3c7040d394013fd38203ea9eb Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Mon, 5 Dec 2016 10:28:11 +0100 Subject: [PATCH] Update the way we start controller to avoid hiding crash reports --- gns3server/web/web_server.py | 15 ++++++++++++--- requirements.txt | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/gns3server/web/web_server.py b/gns3server/web/web_server.py index 57e57a5e..b59a4ef1 100644 --- a/gns3server/web/web_server.py +++ b/gns3server/web/web_server.py @@ -79,7 +79,8 @@ class WebServer: def _run_application(self, handler, ssl_context=None): try: - self._server = self._loop.run_until_complete(self._loop.create_server(handler, self._host, self._port, ssl=ssl_context)) + srv = self._loop.create_server(handler, self._host, self._port, ssl=ssl_context) + self._server, startup_res = self._loop.run_until_complete(asyncio.gather(srv, self._app.startup(), loop=self._loop)) except OSError as e: log.critical("Could not start the server: {}".format(e)) return False @@ -249,6 +250,13 @@ class WebServer: time.sleep(1) # this is to prevent too many request to slow down the server log.debug("UDP server discovery stopped") + @asyncio.coroutine + def _on_startup(self, *args): + """ + Called when the HTTP server start + """ + yield from Controller.instance().start() + def run(self): """ Starts the server. @@ -284,6 +292,9 @@ class WebServer: log.debug("ENV %s=%s", key, val) self._app = aiohttp.web.Application() + # Background task started with the server + self._app.on_startup.append(self._on_startup) + # Allow CORS for this domains cors = aiohttp_cors.setup(self._app, defaults={ # Default web server for web gui dev @@ -311,8 +322,6 @@ class WebServer: self._signal_handling() self._exit_handling() - controller_start = asyncio.async(Controller.instance().start()) - if server_config.getboolean("shell"): asyncio.async(self.start_shell()) diff --git a/requirements.txt b/requirements.txt index e9ebc9ec..41c03da6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ jsonschema>=2.4.0 -aiohttp>=1.1.3 +aiohttp>=1.1.6 aiohttp_cors>=0.4.0 yarl>=0.7.0 Jinja2>=2.7.3