3
$\begingroup$

I was checking the code from example packages, such as demo_nodes_py and found out that there were no destroy_node() or rclpy.shutdown() methods used on the rolling branch when closing the node. Take the talker node as an example [1]. The Jazzy version for instance, does include both methods.

Searching info about it, found a grand change in how SIGINT and SIGTERM are managed in the client library rclpy [2].

I would like to know:

  • Which is the standard way of closing a node: no matter if it is a large node or not, I understand that there might be examples were you want to modify the behaviour, but just for the typical usecase of sending SIGINT.
  • Is this standard behaviour supposed to change in future releases due to the change in the rclpy library?

Thanks in advance

$\endgroup$

1 Answer 1

3
$\begingroup$

Nice work, I think you've already linked well to get at least a partial answer. I'd see the essential part of the diff as:

-    rclpy.init(args=args)
+        with rclpy.init(args=args):

i.e. now it uses the Python with statement and context managers, which are specified in PEP 343.

A quick search for me finds rclpy __enter__() and __exit__() implementations.

Thus code targeting rolling today, or kilted and so on in future, rather than jazzy does not need destroy_node() or rclpy.shutdown() because the context manager should handle it, i.e. I'd be hard pressed to say it's a standard way of closing a node, but the default out of the box now should install SIGINT and SIGTERM handlers and so handle those clean ups or close of nodes for you.

If you really only want to handle SIGINT and not SIGTERM as well, I'd imagine (not tested) that can be done by passing SignalHandlerOptions.SigInt.

If you're actually migrating code, it's unclear if you can leave the old calls to destroy_node() or rclpy.shutdown() safely, it'd be better to remove them as per the updated usages in the commit you linked.

$\endgroup$
2
  • $\begingroup$ Thanks for your feedback @pzrq ! So the idea is that now with the with statement, they have hidden context managers which include common methods such as closing the node correctly, and I suppose even more stuff! How cool is to see the code evolve and check it from inside :o. Appreciate the links as well! Edit: I suppose this changes are targeting rolling and not backported to jazzy, but for future release right? $\endgroup$
    – ÁngeLoGa
    Commented Nov 6 at 9:20
  • $\begingroup$ @ÁngeLoGa Hopefully the ROS2 Developer Guide on Versioning helps you begin to answer your follow up question. $\endgroup$
    – pzrq
    Commented Nov 8 at 5:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.