From 5388d4369555028ef86d11f0eb1b63f3233b6c48 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Thu, 3 Sep 2015 17:41:27 +0200 Subject: [PATCH] Fix closing project when multiple project is open Fix #305 --- gns3server/handlers/api/project_handler.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/gns3server/handlers/api/project_handler.py b/gns3server/handlers/api/project_handler.py index e80339fa0..00346f059 100644 --- a/gns3server/handlers/api/project_handler.py +++ b/gns3server/handlers/api/project_handler.py @@ -33,7 +33,7 @@ log = logging.getLogger() class ProjectHandler: # How many clients has subcribe to notifications - _notifications_listening = 0 + _notifications_listening = {} @classmethod @Route.get( @@ -153,11 +153,12 @@ class ProjectHandler: pm = ProjectManager.instance() project = pm.get_project(request.match_info["project_id"]) - if ProjectHandler._notifications_listening <= 1: + if ProjectHandler._notifications_listening.setdefault(project.id, 0) <= 1: yield from project.close() pm.remove_project(project.id) + del ProjectHandler._notifications_listening[project.id] else: - log.info("Skip project closing, another client is listening for project informations") + log.warning("Skip project closing, another client is listening for project informations") response.set_status(204) @classmethod @@ -203,7 +204,8 @@ class ProjectHandler: response.start(request) queue = project.get_listen_queue() - ProjectHandler._notifications_listening += 1 + ProjectHandler._notifications_listening.setdefault(project.id, 0) + ProjectHandler._notifications_listening[project.id] += 1 response.write("{\"action\": \"ping\"}\n".encode("utf-8")) while True: try: @@ -219,7 +221,8 @@ class ProjectHandler: except asyncio.futures.TimeoutError as e: response.write("{\"action\": \"ping\"}\n".encode("utf-8")) project.stop_listen_queue(queue) - ProjectHandler._notifications_listening -= 1 + if project.id in ProjectHandler._notifications_listening: + ProjectHandler._notifications_listening[project.id] -= 1 @classmethod @Route.get(