rgov
2
If the only use of RosContext is going to be through the with_ros function decorator, then why not simply make the decorator do:
def wrapper(*args, **kwargs):
rospy_and_cpp_init(name)
try:
func(*args, **kwargs)
finally:
shutdown()
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?
1 Like