-
Notifications
You must be signed in to change notification settings - Fork 64
RSDK-2506 Sessions client #301
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
RSDK-2506 Sessions client #301
Conversation
why isn't this being implemented in rust-utils? |
the python sdk can still dial a robot directly without using rust-utils, so we need to implement it here to support sessions for that kind of connection. |
got it |
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.
LGTM assuming testing was done that the robot stopped the base once the python SDK was forcefully killed without warning
src/viam/sessions_client.py
Outdated
if self._disabled: | ||
return | ||
|
||
if event.method_name in [self.client.StartSession.name]: |
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.
do we need to exempt the other methods at https://github.com/viamrobotics/rdk/blob/main/session/doc.go#L71?
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.
ah didn't see this before, will add
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.
Yeah, let me try this with a longer-running command to confirm EDIT: done - works as expected. If you run the following script and abort it, the robot will stop moving straight. # imports / constants ...
async def connect():
creds = Credentials(type="robot-location-secret", payload=SECRET)
opts = RobotClient.Options(refresh_interval=0, dial_options=DialOptions(credentials=creds), log_level=DEBUG)
return await RobotClient.at_address(URI, opts)
async def main():
robot = await connect()
base = Base.from_robot(robot, BASE_NAME)
await base.move_straight(10000, 100)
if __name__ == "__main__":
asyncio.run(main()) |
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.
Just looked over for code quality, didn't actually test.
Looks good! Mostly nits
) | ||
|
||
|
||
async def delay(coro, seconds): |
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.
there's a loop.call_later
function that might be useful here:
loop = asyncio.get_running_loop()
loop.call_later(seconds, coro)
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.
This looked promising, but unfortunately loop.call_later
takes a sync callback and not a co-routine: https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.loop.call_later
if self._lock.locked(): | ||
return | ||
|
||
LOGGER.debug("resetting session") |
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.
[nit] can we make all logs Sentence case
please?
src/viam/sessions_client.py
Outdated
raise | ||
else: | ||
if response is None: | ||
raise GRPCError(status=Status.INTERNAL, message="expected response to start session") |
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.
Same with error messages as with logs: Sentence case
please
pyproject.toml
Outdated
mypy-protobuf = "^3.4.0" | ||
tox = "^4.5.1" | ||
isort = "^5.12.0" | ||
pytest-watcher = "^0.2.6" |
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.
[q] is this needed?
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.
Not strictly, but it was helpful to have this utility when I was spiking out unit tests. I can you remove if you prefer.
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.
Went ahead and removed
For posterity, you should use |
Implements client-side sessions for the python sdk
TODO
Manual Testing
cd
into the repository.testing.py
(or run the curl script below)Find your favorite robot with a drive-able base and replace the
URI, SECRET, BASE_NAME
constants in script above with the relevant parameters.Run the following commands
W A S or D + ENTER
should drive the base without any noticeable lag.