0
$\begingroup$

Rosanswers logo

This question has an answer for roscpp; what is the equivalent solution for Python?

EDIT: I do not want to wait for the service. I want to take one action if the service exists and a different action if it doesn't exist.

A hack might be to wrap a wait_for_service call in a try/catch to catch a ROSException and verify that that ROSException was a timeout, but that's very ugly and I'm not sure what the minimum required timeout should be to ensure that extant topics do not cause the Exception.


Originally posted by BJP on ROS Answers with karma: 100 on 2017-06-01

Post score: 1

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

There is a function in the rospy API to get a list of services: http://docs.ros.org/kinetic/api/rospy/html/rospy.service.ServiceManager-class.html#get_services

I guess this would return a list of all registered services and you could check if the service you are waiting for is in this list.

Edit: I haven't tested the API call I linked in the original answer. I used http://docs.ros.org/kinetic/api/rospy/html/rospy.service.ServiceManager-class.html#get_services

It works for me:

>>> import rosservice
>>> service_list = rosservice.get_service_list()
>>> print service_list
['/rosout/set_logger_level', '/rosout/get_loggers']

Originally posted by Zubin Priyansh with karma: 161 on 2017-06-02

This answer was ACCEPTED on the original site

Post score: 3


Original comments

Comment by NEngelhard on 2017-06-03:
Have you tried this?

Comment by Zubin Priyansh on 2017-06-03:
@NEngelhard I had successfully gotten a list of services in rospy, but now I realize it wasn't with this particular API call. I used this call: http://docs.ros.org/kinetic/api/rosservice/html/rosservice-pysrc.html#get_service_list . I should edit my answer accordingly.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.