From abfb0db6a8fab8ec89236392c4257cb2d36be459 Mon Sep 17 00:00:00 2001 From: Benjamin Tissoires Date: Tue, 13 Feb 2018 13:55:57 +0100 Subject: [PATCH] kete: catch the ServiceUnknown exception in TuhiKeteDevice This allows to have more symmetrical handling of the Searcher and the Listener --- tools/tuhi-kete.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tools/tuhi-kete.py b/tools/tuhi-kete.py index 2052b40..91f7b61 100755 --- a/tools/tuhi-kete.py +++ b/tools/tuhi-kete.py @@ -217,7 +217,13 @@ class TuhiKeteDevice(_DBusObject): self.proxy.StartListening() def stop_listening(self): - self.proxy.StopListening() + try: + self.proxy.StopListening() + except GLib.Error as e: + if (e.domain != 'g-dbus-error-quark' or + e.code != Gio.IOErrorEnum.EXISTS or + Gio.dbus_error_get_remote_error(e) != 'org.freedesktop.DBus.Error.ServiceUnknown'): + raise e def json(self, index): return self.proxy.GetJSONData('(u)', index) @@ -439,15 +445,9 @@ class Listener(Worker): def stop(self): logger.debug(f'{self.device}: stopping listening') - try: - self.device.stop_listening() - self.device.disconnect(self.s1) - self.device.disconnect(self.s2) - except GLib.Error as e: - if (e.domain != 'g-dbus-error-quark' or - e.code != Gio.IOErrorEnum.EXISTS or - Gio.dbus_error_get_remote_error(e) != 'org.freedesktop.DBus.Error.ServiceUnknown'): - raise e + self.device.stop_listening() + self.device.disconnect(self.s1) + self.device.disconnect(self.s2) def _on_device_listening(self, device, pspec): if self.device.listening: