Ask Your Question

Revision history [back]

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

Hello

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():
       rospy.init_node('Test111')


   if __name__=="__main__":
       try:
           TheMain()
       except rospy.ROSInterruptException:
           pass

I tried to use:

rosrun package_name file_namy.py

but I keep getting this error:

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

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