Ask Your Question

Revision history [back]

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


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