Skip to content

Notifier no longer raises handled exceptions in rx_thread #789

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 19, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions can/notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.
Expand Down