-
Notifications
You must be signed in to change notification settings - Fork 267
Description
Bug report
It looks like the callback that can be registered via context.on_shutdown is never called.
Required Info:
- Operating System:
- Ubuntu 22.04
- Installation type:
- binary
- Version or commit hash:
- 4.1.5
- Client library (if applicable):
- rclpy
Steps to reproduce issue
Register a callback to on_shutdown and then try various methods of exiting the node
def shutdown_handler():
print("exit")
def main(args=None):
rclpy.init(args=args)
node = Node("TestNode")
node.context.on_shutdown(shutdown_handler)
rclpy.get_default_context().on_shutdown(shutdown_handler)
rclpy.spin(node)
I tried sending various signals: SIGINT, SIGTERM, SIGQUIT
Expected behavior
exit should be printed twice
Actual behavior
Prints nothing
Additional information
I also tried calling try_shutdown:
try:
rclpy.spin(node)
except (KeyboardInterrupt, rclpy.executors.ExternalShutdownException):
pass
finally:
rclpy.try_shutdown()
But this didn't result into on_shutdown being called either.
If one tries to explicitly shutdown the context:
finally:
node.context.shutdown()
The following error is thrown:
failed to shutdown: rcl_shutdown already called on the given context
Related Issues
This issue is probably related to. But according to the issues I found on_shutdown should be at least called if the node is properly exited (or if try_shutdown is called?)
#532
#1077 <- This is actually what I am looking for as I do want to do some cleanup