Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Errors in callbacks when running async is not calling _on_error()

Abierto
#1,912 1 comentario 1 reacción 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
45/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
python
Área
backend

Línea de trabajo

Lee can/notifier.py alrededor de las líneas 111-137 y sigue la ruta de asyncio desde Notifier._rx_thread, pasando por _on_message_received y call_soon_threadsafe. Revisa la discusión relacionada #1865. El trabajo estará terminado cuando las excepciones del callback de recepción en modo async lleguen a Listener._on_error() y se conserve el comportamiento existente sin async.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

bug

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.

https://github.com/hardbyte/python-can/blob/654a02ae24bfc50bf1bb1fad7aab4aa88763d302/can/notifier.py#L111-L137

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 loop
        if self._loop:
            def rx_handler(msg: Message) -> None:
                try:
                    self._on_message_received(msg)
                except Exception as exc:
                    if not self._on_error(exc):
                        raise
                    else:
                        # It was handled, so only log it
                        logger.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
        ...

Probably related to #1865

Lenguaje dominante
Python
Estrellas
1.6k
Forks
697
Métricas de merge de PR
Sin PR fusionados en 30 d

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de hardbyte/python-can

Todos los issues de hardbyte/python-can

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.