Hang on wait_for_server() on import, but not direct use
I have a function called gripper.py with the lines
grip_r_client = actionlib.SimpleActionClient('r_gripper_controller/gripper_action', Pr2GripperCommandAction)
print "waiting for right gripper server"
grip_r_client.wait_for_server()
Then I have a script, test_gripper.py. If I try to import gripper.py
, the program gets stuck at wait_for_server(). On the other hand, if I just copy those lines into test_gripper.py, or if I do execfile('gripper.py')
, it works.
What's going on?
Edit: here's the full code. I would upload the package, but I don't have enough karma.
gripper.py:
import roslib
roslib.load_manifest('test')
import rospy, actionlib
from pr2_controllers_msgs.msg import Pr2GripperCommandAction
grip_r_client = actionlib.SimpleActionClient('r_gripper_controller/gripper_action',Pr2GripperCommandAction)
print "waiting for right gripper server"
grip_r_client.wait_for_server()
test_gripper.py:
import roslib
roslib.load_manifest('test')
import rospy,actionlib
rospy.init_node('test_gripper')
import gripper
# OR ...
#execfile("gripper.py")
I realize this is non-idiomatic code, and it's really easy to fix the problem (I create a Gripper class, and wait_for_server in its __init__ method), but it's a strange phenomenon.