hardbyte / hardbyte/python-can

Async variant of BusABC?

Đang mở
#1,137 5 bình luận 0 reaction 0 người được giao Xem trên GitHub
api docs
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ả

I am using the asyncio support in `Notifier` which works well on reception of messages. However there is no async variant of `BusABC.send()`. It has a timeout which by default is set to `None` that may block forever according to spec. Not all interfaces seems to be using the timeout parameter and I haven't had any problem using it as-is from async tasks. But it _is_ a potential block which may halt the async event loop if called from an async task. There are other functions in the `BusABC` API that has similar timeouts, like `recv()`.

I guess the first question would be if an async variant of `BusABC.send()` is really needed or not. If the timeout is for all practical purposes not used and sends are immediate, then IMHO there is nothing wrong with this blocking call.

What would be a good approach for async? Make a new `AsyncBus` as wrapper for `BusABC` in the same manner as `ThreadSafeBus` is? I believe due to the nature of async tasks, the `send()` function would need to put the message on a queue and await a signal. A separate (non async) tx thread would be responsible for sending the message using the regular `send()` including traditional timeouts and then signal back to the sleeping async task.

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.