ros2 / rclpy

rclpy (ROS Client Library for Python)
Apache License 2.0
268 stars 221 forks source link

Update the executor to not throw ExternalShutdownException #1279

Open clalancette opened 1 month ago

clalancette commented 1 month ago

This is an issue split out of https://github.com/ros2/examples/pull/379

Currently the rclpy executor can throw an ExternalShutdownException: https://github.com/ros2/rclpy/blob/99f1ce933ddd1677fda8fa602af3684b93f814eb/rclpy/rclpy/executors.py#L689

However, there is really no need to throw an exception at this point that callers of rclpy.spin would need to handle; we could instead just return a value indicating why the spin stopped. This would make it so users need less error-handling code, make this act more like rclcpp (which doesn't throw an exception here), and still provide information in case somebody wants to know why the spin stopped.

Further, we can easily stop throwing an exception here with no impact to downstream consumers. If they aren't handling the exception today, this will just make it a bit more robust. If they are handling ExternalShutdownException today, then that effectively becomes dead code but nothing really breaks.