From 47681f4112a40b052588b3a66c5ea9336070ec85 Mon Sep 17 00:00:00 2001 From: Piotr Date: Sat, 7 Mar 2020 12:01:25 +0000 Subject: [PATCH] Notifier no longer raises handled exceptions in rx_thread --- can/notifier.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/can/notifier.py b/can/notifier.py index 2b909cae7..de2894f64 100644 --- a/can/notifier.py +++ b/can/notifier.py @@ -118,9 +118,9 @@ def _rx_thread(self, bus: BusABC): self.exception = exc if self._loop is not None: self._loop.call_soon_threadsafe(self._on_error, exc) - else: - self._on_error(exc) - raise + raise + elif not self._on_error(exc): + raise def _on_message_available(self, bus: BusABC): msg = bus.recv(0) @@ -134,10 +134,15 @@ def _on_message_received(self, msg: Message): # Schedule coroutine self._loop.create_task(res) - def _on_error(self, exc: Exception): - for listener in self.listeners: - if hasattr(listener, "on_error"): - listener.on_error(exc) + def _on_error(self, exc: Exception) -> bool: + listeners_with_on_error = [ + listener for listener in self.listeners if hasattr(listener, "on_error") + ] + + for listener in listeners_with_on_error: + listener.on_error(exc) + + return bool(listeners_with_on_error) def add_listener(self, listener: Listener): """Add new Listener to the notification list.