From b7dac1bec4ba5d45a65597a6c7248aa8c6c002da Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Tue, 5 May 2015 11:33:47 +0200 Subject: [PATCH] Force closing the event loop to avoid warning with Python 3.4.3 Fix #177 --- gns3server/server.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/gns3server/server.py b/gns3server/server.py index dca8ff29..77c194a9 100644 --- a/gns3server/server.py +++ b/gns3server/server.py @@ -27,6 +27,7 @@ import aiohttp import functools import types import time +import atexit from .web.route import Route from .web.request_handler import RequestHandler @@ -173,6 +174,18 @@ class Server: return yield from embed(globals(), locals(), return_asyncio_coroutine=True, patch_stdout=True) + def _exit_handling(self): + def close_asyncio_loop(): + loop = None + try: + loop = asyncio.get_event_loop() + except AttributeError: + pass + if loop is not None: + loop.close() + + atexit.register(close_asyncio_loop) + def run(self): """ Starts the server. @@ -216,6 +229,8 @@ class Server: self._loop.run_until_complete(self._run_application(self._handler, ssl_context)) self._signal_handling() + self._exit_handling() + if server_config.getboolean("live"): log.info("Code live reload is enabled, watching for file changes") self._loop.call_later(1, self._reload_hook)