Skip to content

Commit

Permalink
don't busy wait
Browse files Browse the repository at this point in the history
Signed-off-by: Brian Chen <[email protected]>
  • Loading branch information
ihasdapie committed Jun 16, 2022
1 parent 20ba9fe commit efcc246
Showing 1 changed file with 5 additions and 21 deletions.
26 changes: 5 additions & 21 deletions ros2param/ros2param/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# limitations under the License.

import sys
import time
import warnings

from rcl_interfaces.msg import ParameterType
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit efcc246

Please sign in to comment.