You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If a Notifier is created using an asyncio loop, any errors that occurs in the receive callbacks will not call the Listener._on_error() callback. It does when not running asyncio.
Looking at Notifier._rx_thread(): When a loop is present it will call Notifier._on_message_received() using the self._loop.call_soon_threadsafe() call. However the except Exception as exc: in line 127 will never be reached, because any errors in the call_soon_threadsafe() callback does not return the exceptions for the function it calls. This in turn implies that when asyncio is enabled, the Listener._on_error() callback won't be called either which is unexpected.
The fix would be to either encapsulate Notifier._on_message_received() in an except block and call the _on_error() call back from it. Another solution is to make it call an extra handler when running async:
def_rx_thread(self, bus: BusABC) ->None:
# determine message handling callable early, not inside while loopifself._loop:
defrx_handler(msg: Message) ->None:
try:
self._on_message_received(msg)
exceptExceptionasexc:
ifnotself._on_error(exc):
raiseelse:
# It was handled, so only log itlogger.debug("suppressed exception: %s", exc)
handle_message: Callable[[Message], Any] =functools.partial(
self._loop.call_soon_threadsafe,
rx_handler, # type: ignore[arg-type]
)
else:
handle_message=self._on_message_received
...
If a
Notifier
is created using an asyncio loop, any errors that occurs in the receive callbacks will not call theListener._on_error()
callback. It does when not running asyncio.Looking at
Notifier._rx_thread()
: When a loop is present it will callNotifier._on_message_received()
using theself._loop.call_soon_threadsafe()
call. However theexcept Exception as exc:
in line 127 will never be reached, because any errors in thecall_soon_threadsafe()
callback does not return the exceptions for the function it calls. This in turn implies that when asyncio is enabled, theListener._on_error()
callback won't be called either which is unexpected.python-can/can/notifier.py
Lines 111 to 137 in 654a02a
The fix would be to either encapsulate
Notifier._on_message_received()
in an except block and call the_on_error()
call back from it. Another solution is to make it call an extra handler when running async:Probably related to #1865
The text was updated successfully, but these errors were encountered: