From 19425b1e9c0376194abba78556b57d98e0307e9d Mon Sep 17 00:00:00 2001 From: Jeremy Date: Tue, 21 Jul 2015 16:02:44 -0600 Subject: [PATCH] Backport: Fixes RuntimeError: Event loop is closed. --- gns3server/server.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/gns3server/server.py b/gns3server/server.py index 77c194a9..ae585abf 100644 --- a/gns3server/server.py +++ b/gns3server/server.py @@ -85,7 +85,8 @@ class Server: """ if self._handler: - yield from self._handler.finish_connections() + yield from self._handler.finish_connections(1.0) + self._handler = None for module in MODULES: log.debug("Unloading module {}".format(module.__name__)) @@ -175,6 +176,10 @@ class Server: yield from embed(globals(), locals(), return_asyncio_coroutine=True, patch_stdout=True) def _exit_handling(self): + """ + Makes sure the asyncio loop is closed. + """ + def close_asyncio_loop(): loop = None try: @@ -226,7 +231,8 @@ class Server: log.info("Starting server on {}:{}".format(self._host, self._port)) self._handler = app.make_handler(handler=RequestHandler) - self._loop.run_until_complete(self._run_application(self._handler, ssl_context)) + server = self._run_application(self._handler, ssl_context) + self._loop.run_until_complete(server) self._signal_handling() self._exit_handling() @@ -245,3 +251,8 @@ class Server: # on Windows when the process gets the SIGBREAK signal # TypeError: async() takes 1 positional argument but 3 were given log.warning("TypeError exception in the loop {}".format(e)) + finally: + if self._handler: + self._loop.run_until_complete(self._handler.finish_connections(1.0)) + server.close() + self._loop.run_until_complete(app.finish())