Skip to content

Conversation

@Alpaca233
Copy link
Collaborator

…al class

@Alpaca233 Alpaca233 marked this pull request as ready for review April 14, 2025 21:40
Copy link
Collaborator

@ianohara ianohara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think using the _update_internal_state() helper is more in line with the rest of the code, and easier for future maintenance, unless I missed a reason why we can't use that. Can you update it if there's not a reason?

return True
except Exception as e:
self.log.error(f"Failed to clear input buffer: {e}")
self._log.error(f"Failed to clear input buffer: {e}")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know about this initially, so I was doing the same for a while, but if you want you can use:

self._log.exception("Failed to clear input buffer")

And as long as you call that in an except clause, it'll take care of printing the exception (and stack trace!) for you.

def reset_input_buffer(self) -> bool:
with self._update_lock:
self.response_buffer.clear()
self._in_waiting = 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the convention here is to run self._update_internal_state() instead of modifying self._in_waiting directly. Can you do that instead? Or does that not work for some reason?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(the idea of self._update_internal_state() is that it tries to keep all the mutating and calculate of fields in one place as much as possible, then all the methods can just call it and not need to know about the particulars of how to update all the internal state.

Copy link
Collaborator

@ianohara ianohara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@hongquanli hongquanli merged commit 8b4551f into Cephla-Lab:master Apr 14, 2025
1 of 2 checks passed
@Alpaca233 Alpaca233 deleted the serial_buffer branch May 6, 2025 01:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants