Skip to content

return values of _send_command and _wait_for_answer_async in cri_controller.py #48

Closed

Description

@TeTi89

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.

class SentCommand(NamedTuple):
    message_id: int
    answer_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:

with self.answer_events_lock:
    if message_id not in self.answer_events:
        return None
    wait_event = self.answer_events[message_id]

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 := await self._wait_for_answer_async(msg_id, timeout=30.0)) is not None:
    logger.debug("Error in Move Joints command: %s", error_msg)
    return False

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

  1. added theissue type on Oct 9, 2026
  2. linked a pull request that will close this issueMultiple event listener handling #49on Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingenhancementNew feature or request

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions