Skip to content

Commit

Permalink
Use context manager form of rclpy.init() (#4813)
Browse files Browse the repository at this point in the history
* Use context manager form of rclpy.init()

Signed-off-by: Shane Loretz <[email protected]>

* Fix indentation

Signed-off-by: Shane Loretz <[email protected]>

---------

Signed-off-by: Shane Loretz <[email protected]>
  • Loading branch information
sloretz authored Oct 16, 2024
1 parent a839c3b commit b5b8578
Showing 1 changed file with 2 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------
Expand Down

0 comments on commit b5b8578

Please sign in to comment.