1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-25 16:28:11 +00:00

Backport: Fixes RuntimeError: Event loop is closed.

This commit is contained in:
Jeremy 2015-07-21 16:02:44 -06:00
parent 439e0df058
commit 19425b1e9c

View File

@ -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())