ros2/rclpy

Pre-Shutdown Hooks / Humble

Opened this issue · 0 comments

Feature request

Feature description

Hooks that run immediately prior to shutdown. It used to be possible prior to humble with:

try:
   rclpy.spin(my.node)
except (KeyboardInterrupt):
   // make some rclpy service calls
   my.node.destroy_node()
   rclpy.shutdown()

It looks like this is no longer possible since context shutdowns happen automagically.

Typical humble code now looks like:

    try:
        rclpy.spin(led_strip.node)
    except (KeyboardInterrupt, rclpy.executors.ExternalShutdownException):
        // context is already gone at this point
        pass
    finally:
        rclpy.try_shutdown()

Implementation considerations

rclpy has an on_shutdown` hook in but that comes too late (i.e. after shutdown).

rclcpp has a pre_shutdown hook: ros2/rclcpp#1714 but this is not available in rclpy.