Nodes not deactivated when process is ended
What I am doing
I am running the ROS Tutorial Writing a Publisher (python).
What I am using
Ubuntu 16.04
ROS kinetic
Python 2.7
What I want to know
I built the code using catkin_make
. When running the simple publisher ("talker") provided in the tutorial (see code down below) and check for running nodes I get
$ rosnode list
/rosout
/talker_9026_1529404131936 # since I set anonymous=True
The talker works fine, the listener gets the data as expected. But when stopping the talker (e.g. press ctr + c or closing the terminal-window) the talker-node does not deactivate and is still visible in rosnode list
. When restarting the node it starts a new node "/talker" with some other number (since anonymous is set True). Setting anonymous=False
does not change this behaviour.
How can I properly end my node when stopping the process? I can end it manually using $ roskill rosmaster
, but that's not what I want.
Talker-code:
#!/usr/bin/env python
# license removed for brevity
import rospy
from std_msgs.msg import String
def talker():
pub = rospy.Publisher('chatter', String, queue_size=10)
rospy.init_node('talker', anonymous=True)
rate = rospy.Rate(10) # 10hz
while not rospy.is_shutdown():
hello_str = "hello world %s" % rospy.get_time()
rospy.loginfo(hello_str)
pub.publish(hello_str)
rate.sleep()
if __name__ == '__main__':
try:
talker()
except rospy.ROSInterruptException:
pass
just making sure: what is the output of
/usr/bin/env python
?I'm using Python 2.7.12: