Repository navigation
driver/python_can: fix the way recv and flush_tx_buffer are called - #78
Conversation
recv and flush_tx_buffer are called
fallenmi
left a comment
There was a problem hiding this comment.
Codex-assisted review.
Reviewed exact head 7d128572aba5be886213d76758c62635dbdb7386. Both transport changes match python-can's contract: recv() accepts seconds or None, and the base flush_tx_buffer() reports unsupported backends with NotImplementedError. The patch passes the timeout through unchanged and catches only that unsupported-operation signal, leaving unexpected write errors on the existing feedback path.
A focused fake-bus oracle changed from recv_timeouts=[12.5, -1] and failed TX feedback on the base to recv_timeouts=[0.0125, None] and successful TX feedback on both the exact head and current merge. A separate RuntimeError flush case still propagated on all trees. The full repository suite passed 58/58 on the PR base, exact head, and current merge; diff and compile checks are clean.
python-can's recv function is supposed to take a timeout in seconds, or None, not in milliseconds or -1.
E.g. the socketcan interface does not have `flush_tx_buffer` implemented. Calling the function without a `try` would cause send operations to fail.
7d12857 to
54a2299
Compare
|
Automated review note — AI-generated (Claude), validated against the live diff. Please sanity-check before acting. Reviewed at head Full report: https://uav.tridgell.net/DevCallReviews/2026_09_17_AIReview/devcall_pr_reviews.html#prpydronecan-78 Verdict: APPROVE — no blockersFour lines, both premises correct, and each proved by mutation against the real driver rather than by reading. Two independent passes reached APPROVE. Both premises verified by running the code. Running the real driver at your head and at its base
A second independent pass reproduced all of this across five python-can versions (4.2.2, 4.3.1, 4.4.0, 4.5.0, 4.6.1) and measured 9.996094 s against 0.010126 s. Premise 1 — the Premise 2 — One correction to be fair to the old code: the virtual peer did still receive the frame before the flush raised, so "all sending was broken" overstates the transmission effect — what actually broke was that every send surfaced a spurious exception to the caller. The fix is correctly scoped: the Notes, none blocking
Dropped as a false positive during validation: I had suggested also catching Checked clean: API contracts read from the installed library rather than from memory ( |
|
Automated review note — AI-generated (Claude), validated against the live diff. Please sanity-check before acting. Re-reviewed on request at the same head Full re-review: https://uav.tridgell.net/DevCallReviews/followups/2026_09_17_2330/devcall_pr_reviews.html#prpydronecan-78 Five things are new, one of which corrects the earlier comment. 1. CI has never run on this PR — a maintainer has to release itThe single The suite does pass at this head — 58 passed run locally on Python 3.14 with python-can 4.6.1 — but that is my run, not the project's, and it should not substitute for CI before merge. 2. Correction to my earlier comment:
|
| probe | base 622229f |
head 54a22990ef |
|---|---|---|
driver.receive(0.01) |
10.0001 s | 0.0101 s |
send_frame() then receive() |
raised NotImplementedError |
OK |
| peer actually received the frame | yes | yes |
driver.receive(None) |
ValueError, swallowed, returned in 4.4 ms |
blocks (correct) |
The 4.3.1 → 4.4.0 boundary was re-bisected from installed sources: 4.3.1 is a docstring-only no-op (bus.py:451), 4.4.0 raises (bus.py:458). One small extra in the fix's favour: can.CanInterfaceNotImplementedError is a subclass of NotImplementedError, so your guard covers that spelling as well. The guard costs 0.110 µs per frame — measured, and negligible.
Nothing in the earlier comment's other notes changed: the bustype= deprecation at :44, the string version comparison at :87, and the absent test coverage for this driver all stand as written.
python-can's recv function is supposed to take a timeout in seconds or None, not in milliseconds or -1.
See issue #77
In addition, in newer versions of
python-can, theflush_tx_bufferraises aNotImplementedErrorfor many interface types like socketcan. I raised an issue requesting a change in this behaviour here: hardbyte/python-can#1922This combination makes
pydronecanunresponsive, and not working for send-operations at all ifpython-canis installed on the system, so I think a workaround like this is warranted.