Closed clalancette closed 2 months ago
While there are still a few outstanding pull requests for this, this has largely been completed in Rolling. Thus I'm going to close this one out. Thanks in particular to @sloretz for all of the reviews in getting this in.
Let's say that you want to create an rclpy node with a publisher and a subscription. In order to do this entirely correctly today, you would have to do the following:
That is, every time we successfully create an entity, we really need to put a
try..finally
block around it to clean up only those parts that we've initialized so far. This is very unwieldy, so we don't actually recommend it in our examples or documentation.However, we should be able to do better. In particular, if all of the initialization, nodes, publishers, subscriptions, services, clients, action servers, and action clients were Python context managers (i.e. they all implemented
__enter__
and__exit__
), this could be cleaned up to something like:Or even better, using a contextlib.ExitStack:
This came out of discussion around https://github.com/ros2/examples/pull/379