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

How to correctly shutdown a rosnode?

asked 2016-12-20 22:12:33 -0500

nansmallgong gravatar image

updated 2016-12-21 02:25:04 -0500

gvdhoorn gravatar image

I test a simple code snippet:

import rospy
import time
import sys
if __name__=="__main__":
  rospy.init_node("a node")
  rospy.signal_shutdown("an exception")

this code will cause /rosout create a file descriptor leak, check with:

lsof -n | grep rosout

which shows a line "rosout 111215 13u sock 0,8 0t0 797756 can't identify protocol".

Each time the code is executed, one more file descriptor leak will be created.

How to prevent this?

edit retag flag offensive close merge delete

Comments

This looks like a duplicate of http://answers.ros.org/question/25039...

ahendrix gravatar image ahendrix  ( 2016-12-20 23:36:50 -0500 )edit

That question is also posted by me, an established socket should be listed like "rosout 111215 111574 10u IPv4 794212 0t0 TCP 127.0.0.1:40341->127.0.0.1:39110 (ESTABLISHED)", but by no means "can't identify protocol".

nansmallgong gravatar image nansmallgong  ( 2016-12-21 00:07:42 -0500 )edit

Hi nansmallgong, can just show me your launch file?

Akhilesh gravatar image Akhilesh  ( 2016-12-30 08:37:54 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-12-27 21:54:21 -0500

nansmallgong gravatar image

Finally I found a tricky solution for the problem.

just sleep for seconds before calling the rospy.signal_shutdown methods

import rospy
import time
import sys
if __name__=="__main__":
  rospy.init_node("a node")
  time.sleep(1)
  rospy.signal_shutdown("an exception")
edit flag offensive delete link more

Comments

1

This is actually a file descriptor leak caused by a bug in roscpp. I have a proposed fix here: https://github.com/ros/ros_comm/pull/...

ahendrix gravatar image ahendrix  ( 2017-11-02 00:57:27 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2016-12-20 22:12:33 -0500

Seen: 1,544 times

Last updated: Dec 27 '16