Skip to content
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

Add optional timeout to client.call() #873

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions rclpy/rclpy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,15 @@ def __init__(
# True when the callback is ready to fire but has not been "taken" by an executor
self._executor_event = False

def call(self, request: SrvTypeRequest) -> SrvTypeResponse:
def call(self, request: SrvTypeRequest, timeout_sec: float = None) -> SrvTypeResponse:
"""
Make a service request and wait for the result.

.. warning:: Do not call this method in a callback or a deadlock may occur.

:param request: The service request.
:return: The service response.
:param timeout_sec: Seconds to wait. If ``None``, then wait forever.
:return: The service response if it doesn't timeout, ``None`` otherwise.
:raises: TypeError if the type of the passed request isn't an instance
of the Request type of the provided service when the client was
constructed.
Expand All @@ -92,7 +93,7 @@ def unblock(future):
# The callback might have been added after the future is completed,
# resulting in the event never being set.
if not future.done():
event.wait()
event.wait(timeout_sec)
if future.exception() is not None:
raise future.exception()
return future.result()
Expand Down