ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

How to terminate python script when the node is shutdown

asked 2012-07-05 23:54:35 -0500

chcorbato gravatar image


I'm using this idiom for checking that the node in my python script is working

while not rospy.is_shutdown():
   do some work

but when I kill the node with rosnode kill the while loop does not exit. I suppose rosnode kill triggers the flag associated with is_shutdown(), but maybe I'm wrong.

Could anyone please clarify me on the issue of finishing nodes and the processes that hold them properly? I've checked previous answers, but maybe I've missed a complete example with code on how to catch and handle the related signals.

Thank you very much in advance

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2012-07-06 03:43:23 -0500

joq gravatar image

That should work.

Node termination notification can be quite slow to arrive. Maybe you didn't wait long enough.

If you invoke a bunch of nodes using roslaunch, typing ^C in that terminal sends the interrupt signal to all of them fairly quickly.

edit flag offensive delete link more



roslaunch sends a sigint I think. rosnode kill uses an xmlrpc request. But anyway, I just did a test and can confirm that the above while loop is perfectly fine for both, C-c and the xmlrpc request.

Lorenz gravatar image Lorenz  ( 2012-07-06 03:53:36 -0500 )edit

Question Tools

1 follower


Asked: 2012-07-05 23:54:35 -0500

Seen: 2,178 times

Last updated: Jul 06 '12