-
Notifications
You must be signed in to change notification settings - Fork 224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make rclpy initialization context-manager aware. #1298
Conversation
This PR does two somewhat controversial things: 1. It adds in a new "rclpy.managed_init" method to rclpy, which would be used with a context manager instead of rclpy.init. I had to do things this way because there is no way (as far as I know) for the callee to know whether it was called within a context manager or not, and I don't think we can reasonably change the semantics of rclpy.init() at this point. 2. It changes the context manager implementation of Context so that it does *not* call init() within itself. This definitely changes the semantics, but as it stands that initialization doesn't make sense because it can't take arguments. I think this change is warranted, though we may have to search through documentation and examples to make sure this doesn't break anything. Signed-off-by: Chris Lalancette <clalancette@gmail.com>
That way, we don't need managed_init() anymore. Signed-off-by: Chris Lalancette <clalancette@gmail.com>
That way we can use context managers, but actually properly clean up, including uninstalling signal handlers. We also switch to tracking node resources in the context, so that when the context goes away, all nodes associated with it are automatically destroyed. Signed-off-by: Chris Lalancette <clalancette@gmail.com>
All right, I've now heavily revamped this based on feedback from @sloretz and @wjwwood . In particular, we now are doing a couple of different things:
And everything will be properly cleaned up after when the context is exited. Please take another look when you get a chance. |
Signed-off-by: Chris Lalancette <clalancette@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking great!
Co-authored-by: Shane Loretz <sloretz@openrobotics.org> Signed-off-by: Chris Lalancette <clalancette@gmail.com>
Co-authored-by: Shane Loretz <sloretz@openrobotics.org> Signed-off-by: Chris Lalancette <clalancette@gmail.com>
Signed-off-by: Chris Lalancette <clalancette@gmail.com>
56ef489
to
103073a
Compare
This PR does two somewhat controversial things:
It adds in a new "rclpy.managed_init" method to rclpy, which would be used with a context manager instead of rclpy.init. I had to do things this way because there is no way (as far as I know) for the callee to know whether it was called within a context manager or not, and I don't think we can reasonably change the semantics of rclpy.init() at this point.
It changes the context manager implementation of Context so that it does not call init() within itself. This definitely changes the semantics, but as it stands that initialization doesn't make sense because it can't take arguments. I think this change is warranted, though we may have to search through documentation and examples to make sure this doesn't break anything.
@sloretz I particularly am interested in your feedback on these changes.