diff --git a/ros2_controllers_test_nodes/ros2_controllers_test_nodes/publisher_forward_position_controller.py b/ros2_controllers_test_nodes/ros2_controllers_test_nodes/publisher_forward_position_controller.py index 9c5fc90a2d..7ea201386c 100644 --- a/ros2_controllers_test_nodes/ros2_controllers_test_nodes/publisher_forward_position_controller.py +++ b/ros2_controllers_test_nodes/ros2_controllers_test_nodes/publisher_forward_position_controller.py @@ -72,14 +72,10 @@ def main(args=None): try: rclpy.spin(publisher_forward_position) - except KeyboardInterrupt: + except (KeyboardInterrupt, rclpy.executors.ExternalShutdownException): print("Keyboard interrupt received. Shutting down node.") except Exception as e: print(f"Unhandled exception: {e}") - finally: - if rclpy.ok(): - publisher_forward_position.destroy_node() - rclpy.shutdown() if __name__ == "__main__": diff --git a/ros2_controllers_test_nodes/ros2_controllers_test_nodes/publisher_joint_trajectory_controller.py b/ros2_controllers_test_nodes/ros2_controllers_test_nodes/publisher_joint_trajectory_controller.py index 01f4642585..c2a38fe4d6 100644 --- a/ros2_controllers_test_nodes/ros2_controllers_test_nodes/publisher_joint_trajectory_controller.py +++ b/ros2_controllers_test_nodes/ros2_controllers_test_nodes/publisher_joint_trajectory_controller.py @@ -212,14 +212,10 @@ def main(args=None): try: rclpy.spin(publisher_joint_trajectory) - except KeyboardInterrupt: + except (KeyboardInterrupt, rclpy.executors.ExternalShutdownException): print("Keyboard interrupt received. Shutting down node.") except Exception as e: print(f"Unhandled exception: {e}") - finally: - if rclpy.ok(): - publisher_joint_trajectory.destroy_node() - rclpy.shutdown() if __name__ == "__main__":