From cf37f1d9398c04e8bd0178ef450afadcff863381 Mon Sep 17 00:00:00 2001 From: Shane Loretz Date: Mon, 14 Oct 2024 18:55:21 -0700 Subject: [PATCH 1/2] Use context manager form of rclpy.init() Signed-off-by: Shane Loretz --- .../Migrating-Python-Package-Example.rst | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/source/How-To-Guides/Migrating-from-ROS1/Migrating-Python-Package-Example.rst b/source/How-To-Guides/Migrating-from-ROS1/Migrating-Python-Package-Example.rst index d4230c615c..96c9598806 100644 --- a/source/How-To-Guides/Migrating-from-ROS1/Migrating-Python-Package-Example.rst +++ b/source/How-To-Guides/Migrating-from-ROS1/Migrating-Python-Package-Example.rst @@ -848,13 +848,11 @@ Your refactored code might look like this: def main(): - rclpy.init() try: - rclpy.spin(Talker()) + with rclpy.init(): + rclpy.spin(Talker()) except (ExternalShutdownException, KeyboardInterrupt): - pass - finally: - rclpy.try_shutdown() + pass Conclusion ---------- From b35208172f4f499eced73ef55d4196b58ca6ac82 Mon Sep 17 00:00:00 2001 From: Shane Loretz Date: Mon, 14 Oct 2024 19:11:59 -0700 Subject: [PATCH 2/2] Fix indentation Signed-off-by: Shane Loretz --- .../Migrating-from-ROS1/Migrating-Python-Package-Example.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/How-To-Guides/Migrating-from-ROS1/Migrating-Python-Package-Example.rst b/source/How-To-Guides/Migrating-from-ROS1/Migrating-Python-Package-Example.rst index 96c9598806..81f23a2d19 100644 --- a/source/How-To-Guides/Migrating-from-ROS1/Migrating-Python-Package-Example.rst +++ b/source/How-To-Guides/Migrating-from-ROS1/Migrating-Python-Package-Example.rst @@ -852,7 +852,7 @@ Your refactored code might look like this: with rclpy.init(): rclpy.spin(Talker()) except (ExternalShutdownException, KeyboardInterrupt): - pass + pass Conclusion ----------