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 Jun 25, 2024
1 parent afb1387 commit e259bcf
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 @@ -83,10 +83,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 @@ -107,6 +108,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 e259bcf

Please sign in to comment.