From 79009b70f56842628c66670ea8ef4fba21a5e0f3 Mon Sep 17 00:00:00 2001 From: Shane Loretz Date: Mon, 14 Oct 2024 18:55:21 -0700 Subject: [PATCH] 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 2f109176f0..69d6864354 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 @@ -850,13 +850,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 ----------