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

shutdown for noetic

asked 2021-01-12 19:22:15 -0500

Jack_motiv gravatar image

Updating to Noetic, having trouble shutting down ROS. Seems like "is_shutdown()" doesn't work, so killing master doesn't take down (some of) the nodes, and I have to kill the processes manually.

[term1]

% roscore
...
started core service [/rosout]

[term2]

% python3
import rospy
rospy.init_node('foo')
print(rospy.is_shutdown())
False

[term3]

% rosnode list
/foo
/rosout

[term1]

^C
[rosout-1] killing on exit
[master] killing on exit
shutting down processing monitor...
... shutting down processing monitor complete
done

[term2]

print(rospy.is_shutdown())
False

[term3]

% rosnode list
ERROR: Unable to communicate with master!
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2021-01-13 18:04:38 -0500

Jack_motiv gravatar image

Thanks for the responses, and sorry for the faulty question (this was using Ctrl-C in the launch window to shutdown, though). Indeed the above example acts the same under Melodic - I was following a red herring tracking down the problem and trying to post a minimal example.

In my real system, I have a Python script that builds a launch file on the fly and gives it to roslaunch. After more experimenting, this seems to be a Python2 vs. 3 difference with subprocess.

If I use this trivial launch file "x.launch":

<launch> 
<node name="rviz" pkg="rviz" type="rviz" respawn="True" output="screen"/>
</launch>

then roslaunch x.launch, it works, and ^C shuts it down.

With a minimal version of my script:

import subprocess
try:
        subprocess.call(('roslaunch', "x.launch"))
except KeyboardInterrupt:
        print("KEYINT")

running with python2 (still Ubuntu20 and Noetic), and stop with ^C:

^CKEYINT
$ [rviz-2] killing on exit
[rosout-1] killing on exit
[master] killing on exit
shutting down processing monitor...
... shutting down processing monitor complete
done

and stuff is properly shut down. But running the same with python3:

^C[rviz-2] killing on exit
KEYINT

it's only killing Rviz, leaving rosmaster and rosout running. It was harder to see that this is what was happening in my full environment that opens various terminals and tabs. If I add "raise" to the exception handler (which in the real version does some cleanup), then it shuts down master and other nodes (with either Py2 or 3).

I suspect this won't be the last surprise Python 3 has in store.

edit flag offensive delete link more
0

answered 2021-01-13 10:03:15 -0500

sloretz gravatar image

Updating to Noetic, having trouble shutting down ROS

Are you saying you saw killing the roscore kill all nodes in a previous version of ROS? If so, which version?

I see the same behavior on Melodic. roscore closing does not cause all the nodes connected to it to shutdown. Only a signal within the process does that.

>>> print(rospy.is_shutdown())
False
>>> rospy.signal_shutdown('foobar')
>>> print(rospy.is_shutdown())
True
edit flag offensive delete link more

Comments

1

roscore will take down all processes launched by it after a ctrl+c, but that's different from what the OP describes.

So I agree with @sloretz here.

gvdhoorn gravatar image gvdhoorn  ( 2021-01-13 10:17:53 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2021-01-12 19:22:15 -0500

Seen: 762 times

Last updated: Jan 13 '21