Errors in callbacks when running async is not calling _on_error()
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 45/100
Direzione di ricerca
Leggi can/notifier.py intorno alle righe 111-137 e segui il percorso asyncio da Notifier._rx_thread attraverso _on_message_received e call_soon_threadsafe. Esamina la discussione correlata #1865. Il lavoro è completato quando le eccezioni del callback di ricezione in modalità async raggiungono Listener._on_error() preservando il comportamento esistente non-async.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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 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
- Lingua principale
- Python
- Stelle
- 1.6k
- Fork
- 697
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di hardbyte/python-can
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
hardbyte/python-can#2103 ·
-
bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
hardbyte/python-can#2077 · 1 commento · 1 reazione ·
-
bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 68/100
hardbyte/python-can#1922 · 1 reazione ·
-
enhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 30/100
hardbyte/python-can#2102 ·
-
bug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
hardbyte/python-can#2092 ·
Tutte le issue di hardbyte/python-can
Issue simili
-
area: harness bug status: needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
Human-Agent-Society/reef#625 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 80/100
learningequality/kolibri#15351 · 2 commenti ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
Name consistency Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
eellak/triplestore#65 · 1 commento ·