-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
make hamilton heater shaker async #425
base: main
Are you sure you want to change the base?
make hamilton heater shaker async #425
Conversation
async def _send_command(self, command: str, **kwargs): | ||
assert len(command) == 2, "Command must be 2 characters long" | ||
|
||
args = "".join([f"{key}{value}" for key, value in kwargs.items()]) | ||
await asyncio.to_thread(self.io.write, f"T{self.shaker_index}{command}id{str(self.command_id).zfill(4)}{args}".encode()) | ||
|
||
self.command_id = (self.command_id + 1) % 10_000 | ||
response = await asyncio.to_thread(self.io.read) | ||
return response |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually i don't think the read or write themselves take so long and introducing multithreading leads to potential complications
i think it's better to do many small reads and asyncio.sleep in between
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good idea!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think it's better to do many small reads and asyncio.sleep in between
Shouldn't the read be awaitable? Such that a await self.io.read()
should be sufficient? Otherwise each backend using the io layer needs to implement this logic again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better idea, will go with that
just found out this also breaks .decode on get_temperature |
tested with 8x hhs box