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

Nodes not deactivated when process is ended

asked 2018-06-19 06:23:06 -0500

benjamin gravatar image

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
edit retag flag offensive close merge delete

Comments

just making sure: what is the output of /usr/bin/env python?

gvdhoorn gravatar image gvdhoorn  ( 2018-06-19 09:36:53 -0500 )edit

I'm using Python 2.7.12:

benjamin@ubuntu:~$ /usr/bin/env python

Python 2.7.12 (default, Dec  4 2017, 14:50:18) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
benjamin gravatar image benjamin  ( 2018-06-19 10:39:10 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-06-20 04:06:45 -0500

benjamin gravatar image

updated 2018-06-22 02:49:07 -0500

Due to my specific terminal-settings pressing ctr + c did not exit the process entirely, but only stopped it (as ctr + z in default does). Therefore my node was not ended from being active. Having stopped the process (ctr + z in default) even closing the terminal does not end the process.

Still my question is how can I end one node entirely if I only stopped it in the first place?

edit flag offensive delete link more

Comments

1

For completeness, see What is the difference between Ctrl-z and Ctrl-c in the terminal? for some background on ctrl+z.

If you suspend all your processes by default, you could kill them with kill %1 fi. But see the Ask Ubuntu post.

gvdhoorn gravatar image gvdhoorn  ( 2018-06-22 02:52:39 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2018-06-19 06:18:41 -0500

Seen: 388 times

Last updated: Jun 22 '18