Are calls to rospy ServiceProxy thread-safe?

asked 2015-06-10 04:07:50 -0600

Andreas Antener gravatar image

From the documentation I understand that the underlying rospy service has to be thread-safe. However, I'm having trouble when multiple threads access the same ServiceProxy instance. I get various errors, all of them originating from the tcpros_base.py implementation (see below).

Is it necessary to synchronize on application level when accessing a ServiceProxy? Would it make any difference if I use persistent connections?

Any help is appreciated

Cheers

-- ada

Example 1

  File "/opt/ros/indigo/lib/python2.7/dist-packages/rospy/impl/tcpros_service.py", line 435, in __call__
    return self.call(*args, **kwds)
  File "/opt/ros/indigo/lib/python2.7/dist-packages/rospy/impl/tcpros_service.py", line 512, in call
    transport.send_message(request, self.seq)
  File "/opt/ros/indigo/lib/python2.7/dist-packages/rospy/impl/tcpros_base.py", line 636, in send_message
    self.write_buff.truncate(0)
AttributeError: 'NoneType' object has no attribute 'truncate'

Example 2

  File "/opt/ros/indigo/lib/python2.7/dist-packages/rospy/impl/tcpros_service.py", line 435, in __call__
    return self.call(*args, **kwds)
  File "/opt/ros/indigo/lib/python2.7/dist-packages/rospy/impl/tcpros_service.py", line 512, in call
    transport.send_message(request, self.seq)
  File "/opt/ros/indigo/lib/python2.7/dist-packages/rospy/impl/tcpros_base.py", line 635, in send_message
    self.write_data(self.write_buff.getvalue())
  File "/opt/ros/indigo/lib/python2.7/dist-packages/rospy/impl/tcpros_base.py", line 659, in write_data
    raise TransportTerminated(str(errno)+msg)
TransportTerminated: 32Broken pipe

Example 3

  File "/opt/ros/indigo/lib/python2.7/dist-packages/rospy/impl/tcpros_service.py", line 435, in __call__
    return self.call(*args, **kwds)
  File "/opt/ros/indigo/lib/python2.7/dist-packages/rospy/impl/tcpros_service.py", line 528, in call
    transport.close()
  File "/opt/ros/indigo/lib/python2.7/dist-packages/rospy/impl/tcpros_base.py", line 807, in close
    self.socket.close()
AttributeError: 'NoneType' object has no attribute 'close'
edit retag flag offensive close merge delete