kete: catch the ServiceUnknown exception in TuhiKeteDevice

This allows to have more symmetrical handling of the Searcher and
the Listener
This commit is contained in:
Benjamin Tissoires 2018-02-13 13:55:57 +01:00
parent de033c3b6a
commit abfb0db6a8
1 changed files with 10 additions and 10 deletions

View File

@ -217,7 +217,13 @@ class TuhiKeteDevice(_DBusObject):
self.proxy.StartListening() self.proxy.StartListening()
def stop_listening(self): 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): def json(self, index):
return self.proxy.GetJSONData('(u)', index) return self.proxy.GetJSONData('(u)', index)
@ -439,15 +445,9 @@ class Listener(Worker):
def stop(self): def stop(self):
logger.debug(f'{self.device}: stopping listening') logger.debug(f'{self.device}: stopping listening')
try: self.device.stop_listening()
self.device.stop_listening() self.device.disconnect(self.s1)
self.device.disconnect(self.s1) self.device.disconnect(self.s2)
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
def _on_device_listening(self, device, pspec): def _on_device_listening(self, device, pspec):
if self.device.listening: if self.device.listening: