Ask Your Question
0

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

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

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

1 Answer

Sort by ยป oldest newest most voted
0

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

Stats

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

Seen: 24 times

Last updated: Jan 20