From 81e570931adc37054460e3f05d0325888050e386 Mon Sep 17 00:00:00 2001 From: Jonathan Weth Date: Thu, 23 Jul 2020 14:41:55 +0200 Subject: Implement bi-directional stopping of sessions --- service.py | 2 ++ session.py | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/service.py b/service.py index 7b4ba49..1faae4d 100755 --- a/service.py +++ b/service.py @@ -72,6 +72,8 @@ class RWAService(dbus.service.Object): running = session.vnc_process_running if running: print("Session is running") + elif session.status_text == "stopped" and session.pid in self.sessions: + del self.sessions[session.pid] else: print("Session is dead.") diff --git a/session.py b/session.py index a6c27c5..40a091f 100644 --- a/session.py +++ b/session.py @@ -152,7 +152,12 @@ class Session: r = requests.get( STATUS_URL, params={"id": self.session_id}, headers=self._api_headers ) - self.status_text = r.json()["status"] + + if r.status_code in (401, 402, 403, 404, 405): + # Session doesn't exist anymore, so stop it local + self.stop(triggered=True) + else: + self.status_text = r.json()["status"] def push(self): """Update status: Push status to Django.""" @@ -195,6 +200,8 @@ class Session: STOP_URL, params={"id": self.session_id}, headers=self._api_headers ) + self.status_text = "stopped" + # Delete self del self -- cgit v1.2.3