Ask Your Question

How to run a node that is needed for a single task then exit?

asked 2020-01-19 15:16:38 -0500


I am trying to use rosrun to run a node that does something then exits. Here is a simple example:

   #!/usr/bin/env python

   import rospy
   from geometry_msgs.msg import Twist
   from turtlesim.msg import Pose

   def TheMain():

   if __name__=="__main__":
       except rospy.ROSInterruptException:

I tried to use:

rosrun package_name

but I keep getting this error:

Exception in thread Thread-3:
Traceback (most recent call last):

  File "/usr/lib/python2.7/", line 801, in __bootstrap_inner
  File "/usr/lib/python2.7/", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/impl/", line 154, in run
    (client_sock, client_addr) = self.server_sock.accept()
  File "/usr/lib/python2.7/", line 206, in accept
    sock, addr = self._sock.accept()
  File "/usr/lib/python2.7/", line 174, in _dummy
    raise error(EBADF, 'Bad file descriptor')
error: [Errno 9] Bad file descriptor
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2020-01-20 02:31:11 -0500

gvdhoorn gravatar image

It's likely this does actually work, but the problem is the fact your node (Test111) exits too soon for rospy.init_node(..) to successfully complete the initialisation. It is shutdown before it's complete, leading to some resources to already have been deleted (such as that socket), which leads to errors such as the one you show.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2020-01-19 15:16:38 -0500

Seen: 24 times

Last updated: Jan 20