hardbyte / hardbyte/python-can

Timeout in Notifier does not work as expected

Đang mở
#1,932 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
bug
Ngôn ngữ chính
Python
Star
1.6k
Fork
697
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

### 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](https://github.com/hardbyte/python-can/blob/main/can/bus.py#L110) on timeout it returns `None` that is currently being discarded in `Notifier._rx_thread` as defined [here](https://github.com/hardbyte/python-can/blob/main/can/notifier.py#L123).

### To Reproduce
```python
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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.