Why should we use destroy_node() for Python nodes in ROS2?

asked 2020-06-04 08:18:10 -0500

Hi everyone,

In the ROS2 examples using rclpy (for example the subscriber example), in the main function I always see the use of the rclpy destroy_node() method.

def main(args=None):
    rclpy.init(args=args)

    minimal_subscriber = MinimalSubscriber()

    rclpy.spin(minimal_subscriber)

    # Destroy the node explicitly
    # (optional - otherwise it will be done automatically
    # when the garbage collector destroys the node object)
    minimal_subscriber.destroy_node()
    rclpy.shutdown()

To me the explanation in the comment does not give much info.

I've tried to run the code without this line to see if something would happen, and I got no error so far.

So:

Why should we use destroy_node() before calling rclpy.shutdown()?

Can I expect any kind of issue if I don't explicitely destroy nodes (if I just shutdown ROS and exit after)?

Also, is this practice temporary, and will this line be removed from examples and tutorials in the future?

Thanks!

edit retag flag offensive close merge delete