Skip to content

Commit

Permalink
Handle spin() ExternalShutdownException. (#378)
Browse files Browse the repository at this point in the history
When an rclpy executor is spinning, it can shutdown
by raising an ExternalShutdownException.  Handle that
in wait_for_topics.py so that downstream consumers don't
end up throwing an exception themselves.

Signed-off-by: Chris Lalancette <[email protected]>
  • Loading branch information
clalancette authored Aug 29, 2023
1 parent 760e219 commit 75952a8
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion launch_testing_ros/launch_testing_ros/wait_for_topics.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,15 @@ def __init__(self, topic_tuples, timeout=5.0, messages_received_buffer_length=10
self._prepare_ros_node()

# Start spinning
self.__ros_spin_thread = Thread(target=self.__ros_executor.spin)
self.__ros_spin_thread = Thread(target=self._spin_handle_external_shutdown)
self.__ros_spin_thread.start()

def _spin_handle_external_shutdown(self):
try:
self.__ros_executor.spin()
except rclpy.executors.ExternalShutdownException:
pass

def _prepare_ros_node(self):
node_name = '_test_node_' + ''.join(
random.choices(string.ascii_uppercase + string.digits, k=10)
Expand Down

0 comments on commit 75952a8

Please sign in to comment.