Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Timeout in Notifier does not work as expected

未关闭
#1,932 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
python
领域
networking

调研方向

从 can/bus.py 中链接的 BusABC.recv(timeout) 定义和 can/notifier.py 中的接收循环开始,然后运行提供的 virtual-bus 复现。跟踪在 listener callbacks 之前如何处理 timeout 结果。当约定的 timeout 行为已实现,并且示例或适当的测试证明 listener 可以处理 timeout 时,即视为完成。

由索引模型根据 Issue 内容生成。

描述

bug
Describe the bug

I think, though being not sure, that the timeout in Notifier does not work as expected.
From the definition of BusABC.recv(timeout) in here on timeout it returns None that is currently being discarded in Notifier._rx_thread as defined here.

To Reproduce
import time
import can

class MyListener(can.Listener):
    def on_message_received(self, msg: can.Message) -> None:
        if msg is None:
            print("Timeout occurred.")
        else:
            print(f'Message received: {msg}')

def main():
    with can.Bus(interface="virtual", receive_own_messages=True) as bus:
        print_listener = MyListener()
        notifier = can.Notifier(bus, [print_listener], timeout=1.0)
        time.sleep(2.0)
        bus.send(can.Message(arbitration_id=1, is_extended_id=False))
        notifier.stop()


if __name__ == "__main__":
    main()
Expected behaviour

I expect Listener to call "Timeout occurred." in the provided example.
Currently on_message_received is not called on timeout.

I would welcome discussion and help about how to realize timeout behaviour in Listener - Notifier architecture. I think there should be a way to let Listeners handle being starved.

主要语言
Python
星标
1.6k
派生
697
PR 合并指标
30 天内没有已合并 PR

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

hardbyte/python-can 的其他 Issue

查看 hardbyte/python-can 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。