From 5b457c3083b4ba937e3f04b670d045a4f527559a Mon Sep 17 00:00:00 2001 From: Keng12 <43130728+Keng12@users.noreply.github.com> Date: Fri, 29 Apr 2022 23:52:30 +0200 Subject: [PATCH] Fix long wait during shutdown in WaitForTopics (#314) Signed-off-by: Keng12 --- .../launch_testing_ros/wait_for_topics.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/launch_testing_ros/launch_testing_ros/wait_for_topics.py b/launch_testing_ros/launch_testing_ros/wait_for_topics.py index 170e185d4..14cac086d 100644 --- a/launch_testing_ros/launch_testing_ros/wait_for_topics.py +++ b/launch_testing_ros/launch_testing_ros/wait_for_topics.py @@ -59,8 +59,7 @@ def __init__(self, topic_tuples, timeout=5.0): self._prepare_ros_node() # Start spinning - self.__running = True - self.__ros_spin_thread = Thread(target=self._spin_function) + self.__ros_spin_thread = Thread(target=self.__ros_executor.spin) self.__ros_spin_thread.start() def _prepare_ros_node(self): @@ -69,19 +68,15 @@ def _prepare_ros_node(self): self.__ros_node = _WaitForTopicsNode(name=node_name, node_context=self.__ros_context) self.__ros_executor.add_node(self.__ros_node) - def _spin_function(self): - while self.__running: - self.__ros_executor.spin_once(1.0) - def wait(self): self.__ros_node.start_subscribers(self.topic_tuples) return self.__ros_node.msg_event_object.wait(self.timeout) def shutdown(self): - self.__running = False + # Shutdown context before joining thread + self.__ros_context.try_shutdown() self.__ros_spin_thread.join() self.__ros_node.destroy_node() - rclpy.shutdown(context=self.__ros_context) def topics_received(self): """Topics that received at least one message."""