Pre-Shutdown Hooks / Humble
Opened this issue · 0 comments
stonier commented
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.
- #830
- #844
- https://github.com/ros2/demos/blob/rolling/demo_nodes_py/demo_nodes_py/topics/talker.py#L44-L50
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
.