Shutting down gracefully in RCLPy
I have a node which is responsible for some CAN bus stuff. This is its only responsibility. I want the node to crash violently if the CAN bus somehow is not working. It's written in Python. This is what I have:
if not self.can_handler.init_can():
self.get_logger().fatal('Failed to initialize CAN interface')
rclpy.try_shutdown()
return
This crashes, but only because the python class constructor then tries to make timers and publishers and things, which it can't since the context is cancelled. I would much prefer if the node went "nope, stop the presses, shut it down" and then _didn't_ try to act as if everything is fine. Is there a nicer way to get that done in rclpy?