call service std_srvs/SetBool, get error: [Errno 9] Bad file descriptor

asked 2018-11-30 16:51:01 -0600

Mingyi gravatar image

I am trying to use std_srvs.srv.SetBool with following python implementation

#!/usr/bin/env python

import rospy
from std_srvs.srv import SetBool

counter = 0

def handle_reset(req):
    global counter
    if req.data:
        counter = 1
        return True, "counter is reset"
    return False, "counter is not reset"

if __name__ == '__main__':
    rospy.init_node('number_counter')

    service = rospy.Service("/reset_number_count", SetBool, handle_reset)

    rospy.spin()

I use rosrun to run the script. Use rosservice call /reset_number_count "data: false" and get following error

success: False
message: "counter is not reset"
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

Is it possible that I miss some packages?

My system: Ubuntu 18.04, ROS Melodic in VirtualBox

ROS environment variables:
ROS_ETC_DIR=/opt/ros/melodic/etc/ros
ROS_ROOT=/opt/ros/melodic/share/ros
ROS_MASTER_URI=http://localhost:11311
ROS_VERSION=1
ROS_PYTHON_VERSION=2
ROS_PACKAGE_PATH=/home/mingyi/catkin_ws/src:/opt/ros/melodic/share
ROSLISP_PACKAGE_DIRECTORIES=/home/mingyi/catkin_ws/devel/share/common-lisp
ROS_DISTRO=melodic
edit retag flag offensive close merge delete

Comments

Is it possible that I miss some packages?

This looks more like an issue with the network stack.

gvdhoorn gravatar image gvdhoorn  ( 2018-12-01 02:55:56 -0600 )edit

Sorry, I am just a beginner to Ros... What do you mean network stack?

Mingyi gravatar image Mingyi  ( 2018-12-01 14:50:34 -0600 )edit
1

I'm not entirely sure yet this is something "in ROS". There seems to be an issue with the code trying to open a socket.

Is there anything special about your setup?

gvdhoorn gravatar image gvdhoorn  ( 2018-12-03 04:20:17 -0600 )edit