From b5b8578c2505b96dd724500d374bdc230fe1a61d Mon Sep 17 00:00:00 2001 From: Shane Loretz Date: Tue, 15 Oct 2024 18:08:39 -0700 Subject: [PATCH] Use context manager form of rclpy.init() (#4813) * Use context manager form of rclpy.init() Signed-off-by: Shane Loretz * Fix indentation Signed-off-by: Shane Loretz --------- Signed-off-by: Shane Loretz --- .../Migrating-Python-Package-Example.rst | 6 ++---- 1 file changed, 2 insertions(+), 4 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..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 @@ -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() Conclusion ----------