# Revision history [back]

Your callback should only look like this:

def listener_callback(self):
self.destroy_node()


You can check that the node has been killed through command line: ros2 node list

Note that the rclpy.spin(minimal_action_server) will not terminate even if you kill the node

Your callback should only look like this:

def listener_callback(self):
self.destroy_node()


I tested this with the examples_rclpy_minimal_publisher/publisher_member_function. Here for example you can call self.destroy_node() in the timer callback after N messages have been published.

def timer_callback(self):

if self.i > 5:
self.destroy_node()
return

msg = String()
msg.data = 'Hello World: %d' % self.i
self.publisher_.publish(msg)
self.get_logger().info('Publishing: "%s"' % msg.data)
self.i += 1


You can check that the node has been killed through command line: ros2 node list

Note that the rclpy.spin(minimal_action_server) will not terminate even if you kill the node