Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

オープン
#1,912 コメント 1 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
python
領域
backend

調査の方向性

can/notifier.py の 111〜137 行付近を読み、Notifier._rx_thread から _on_message_received、call_soon_threadsafe へ続く asyncio の経路を追跡してください。関連する #1865 の議論を確認してください。async モードでの受信コールバックの例外が Listener._on_error() に到達し、既存の非 async の動作が維持されれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
Python
スター
1.6k
フォーク
697
PR マージ指標
30日以内にマージされた PR はありません

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

hardbyte/python-can のほかの issue

hardbyte/python-can の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。