You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
return values of _send_command and _wait_for_answer_async in cri_controller.py #48
While reading cri_controller.py I noticed two things I'd like to discuss.
1. _send_command() returns only a message_id
In most call sites the returned message_id is only used to look up the asyncio.Event in _wait_for_answer() / _wait_for_answer_async(), which has to take the lock and search answer_events again.
Proposal: return the event together with the id, e.g.
classSentCommand(NamedTuple):
message_id: intanswer_event: asyncio.Event|None# None if register_answer=False
The wait functions could then use the event directly and skip the lookup.
2. _wait_for_answer_async() uses None for "success"
The docstring says None means "an answer was received with no error". However, the function also returns None here:
So if someone calls _send_command(command) and forgets register_answer=True, _wait_for_answer_async() returns None and the caller treats the command as successfully acknowledged, although nothing was waited for.
It also makes call sites hard to read, because is not None means "error":
msg_id=self._send_command(command, True)
if (error_msg:=awaitself._wait_for_answer_async(msg_id, timeout=30.0)) isnotNone:
logger.debug("Error in Move Joints command: %s", error_msg)
returnFalse
Possible directions:
A. Raise on failure (e.g. CommandRejectedError, AnswerTimeoutError, ValueError for an unregistered id) and return the answer on success.
B. Return a small result object (ok: bool, message: str | None).
C. Keep the current return type, but at least raise for an unregistered message_id, since that is a programming error rather than a robot answer.
Combined with point 1, the "unregistered id" case could disappear entirely (no event, nothing to wait on).
Activity