Hey folks, I was hoping to get some feedback from others on a new bit of code I’ve written:
The goal is to have clean and consistent startup & shutdown behavior for python nodes. The catch is that I want this to work when I am using bindings to C++ ROS code. Therefore, I need the C++ ros::initialize to be called, hence the little roscpp_initializer you see here.
Do you think using a context manager is a good idea here? Do you have something similar to this in your code base? Thoughts on when this might fail/be a bad idea?
Otherwise if there’s another use for RosContext, a more descriptive name like RosNode might be more readable:
with RosNode("talker"):
rospy.Publisher(...)
Is it possible to have multiple RosContexts executing in parallel, for instance in an asyncio or threaded program? If so, how does rospy.Publisher know which to associate with?
What about just having rospy_and_cpp_init use atexit.register() to shutdown the node cleanly when the program terminates?