Skip to content

Commit b8ca212

Browse files
authored
Notifier no longer raises handled exceptions in rx_thread (#789)
1 parent 7780242 commit b8ca212

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

can/notifier.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ def _rx_thread(self, bus: BusABC):
118118
self.exception = exc
119119
if self._loop is not None:
120120
self._loop.call_soon_threadsafe(self._on_error, exc)
121-
else:
122-
self._on_error(exc)
123-
raise
121+
raise
122+
elif not self._on_error(exc):
123+
raise
124124

125125
def _on_message_available(self, bus: BusABC):
126126
msg = bus.recv(0)
@@ -134,10 +134,15 @@ def _on_message_received(self, msg: Message):
134134
# Schedule coroutine
135135
self._loop.create_task(res)
136136

137-
def _on_error(self, exc: Exception):
138-
for listener in self.listeners:
139-
if hasattr(listener, "on_error"):
140-
listener.on_error(exc)
137+
def _on_error(self, exc: Exception) -> bool:
138+
listeners_with_on_error = [
139+
listener for listener in self.listeners if hasattr(listener, "on_error")
140+
]
141+
142+
for listener in listeners_with_on_error:
143+
listener.on_error(exc)
144+
145+
return bool(listeners_with_on_error)
141146

142147
def add_listener(self, listener: Listener):
143148
"""Add new Listener to the notification list.

0 commit comments

Comments
 (0)