Skip to content

Commit

Permalink
Client:call generates TimeoutError exception when it is timed out.
Browse files Browse the repository at this point in the history
Signed-off-by: Tomoya Fujita <[email protected]>
  • Loading branch information
fujitatomoya committed Apr 13, 2024
1 parent 7639215 commit a13ba99
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion rclpy/rclpy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,11 @@ def call(
:param request: The service request.
:param timeout_sec: Seconds to wait. If ``None``, then wait forever.
:return: The service response, or None if timed out.
:return: The service response.
: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.
:raises: TimeoutError if the response is not available within the timeout.
"""
if not isinstance(request, self.srv_type.Request):
raise TypeError()
Expand All @@ -105,6 +106,7 @@ def unblock(future):
if not event.wait(timeout_sec):
# Timed out. remove_pending_request() to free resources
self.remove_pending_request(future)
raise TimeoutError()
if future.exception() is not None:
raise future.exception()
return future.result()
Expand Down
6 changes: 3 additions & 3 deletions rclpy/test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,11 @@ def _service(request, response):
executor_thread = threading.Thread(
target=TestClient._spin_rclpy_node, args=(self.node, executor))
executor_thread.start()
result = cli.call(GetParameters.Request(), 0.5)
self.assertTrue(result is None)
with self.assertRaises(TimeoutError):
cli.call(GetParameters.Request(), 0.5)
finally:
executor.shutdown()
executor_thread.join()
finally:
self.node.destroy_client(cli)
self.node.destroy_service(srv)

Expand Down

0 comments on commit a13ba99

Please sign in to comment.