Blocking service callbacks
Hello everyone. I have been doing experiments with ROS services and currently I have this:
"""services_node.py"""
#!/usr/bin/env python
import time
import rospy
from beginner_tutorials.srv import *
def handle_action_1(request):
print "doing action 1"
time.sleep(2)
return Action1Response()
def handle_action_2(request):
print "doing action 2"
return Action2Response()
if __name__ == "__main__":
rospy.init_node("services_node")
action_1 = rospy.Service("action_1", Action1, handle_action_1)
action_2 = rospy.Service("action_2", Action2, handle_action_2)
rospy.spin()
"""caller_1.py"""
#!/usr/bin/env python
import rospy
from beginner_tutorials.srv import *
rospy.wait_for_service("action_2")
action_2 = rospy.ServiceProxy('action_2', Action2)
i = 0
while True:
print "take %d" % i
print "calling for action_2"
action_2()
i = i + 1
"""caller_2.py"""
#!/usr/bin/env python
import rospy
from beginner_tutorials.srv import *
rospy.wait_for_service("action_1")
action_1 = rospy.ServiceProxy('action_1', Action1)
i = 0
while True:
print "take %d" % i
print "calling for action_1"
action_1()
i = i + 1
This nodes are basically a node that publishes two services, called "action_1" and "action_2", and two nodes that constantly call those services. By the way, the Action1 and Action2 services are empty services, with just a "---" in the .srv files.
The problem I see is that when I run these nodes, the caller_1 node shows the "calling for action_1" every two seconds, which makes sense for me. But, as far as I know, I would expect the caller_2 node to print its text every two seconds, since the services_node is "busy" with the callback for action_1. But what I see is that the caller_2 node works as if was alone, without waiting for the response.
Can you explain this please? I thought service callbacks were blocking, since it's just one node who is answering those services, but it seems the callbacks are not blocking in this case.