diff --git a/ros2param/ros2param/api/__init__.py b/ros2param/ros2param/api/__init__.py index 95df33975..683d4a1b4 100644 --- a/ros2param/ros2param/api/__init__.py +++ b/ros2param/ros2param/api/__init__.py @@ -13,7 +13,6 @@ # limitations under the License. import sys -import time import warnings from rcl_interfaces.msg import ParameterType @@ -41,20 +40,9 @@ def get_value(*, parameter_value): return value -def busy_wait_client(client, node): - timeout_sec = 5 - prev = time.time() - while not (client.services_are_ready() or timeout_sec < 0): - client.wait_for_services(timeout_sec=0.1) - rclpy.spin_once(node) - timeout_sec -= prev - time.time() - if not client.services_are_ready(): - raise RuntimeError('Could not reach parameter services') - - def load_parameter_file(*, node, node_name, parameter_file, use_wildcard): client = AsyncParameterClient(node, node_name) - busy_wait_client(client, node) + client.wait_for_services(timeout_sec=5.0) future = client.load_parameter_file(parameter_file, use_wildcard) parameters = list(parameter_dict_from_yaml_file(parameter_file, use_wildcard).values()) rclpy.spin_until_future_complete(node, future) @@ -77,8 +65,7 @@ def load_parameter_file(*, node, node_name, parameter_file, use_wildcard): def call_describe_parameters(*, node, node_name, parameter_names=None): client = AsyncParameterClient(node, node_name) - busy_wait_client(client, node) - + client.wait_for_services(timeout_sec=5.0) future = client.describe_parameters(parameter_names) rclpy.spin_until_future_complete(node, future) response = future.result() @@ -90,8 +77,7 @@ def call_describe_parameters(*, node, node_name, parameter_names=None): def call_get_parameters(*, node, node_name, parameter_names): client = AsyncParameterClient(node, node_name) - busy_wait_client(client, node) - + client.wait_for_services(timeout_sec=5.0) future = client.get_parameters(parameter_names) rclpy.spin_until_future_complete(node, future) response = future.result() @@ -103,8 +89,7 @@ def call_get_parameters(*, node, node_name, parameter_names): def call_set_parameters(*, node, node_name, parameters): client = AsyncParameterClient(node, node_name) - busy_wait_client(client, node) - + client.wait_for_services(timeout_sec=5.0) future = client.set_parameters(parameters) rclpy.spin_until_future_complete(node, future) response = future.result() @@ -116,8 +101,7 @@ def call_set_parameters(*, node, node_name, parameters): def call_list_parameters(*, node, node_name, prefixes=None): client = AsyncParameterClient(node, node_name) - busy_wait_client(client, node) - + client.wait_for_services(timeout_sec=5.0) future = client.list_parameters(prefixes=prefixes) rclpy.spin_until_future_complete(node, future) response = future.result()