Ask Your Question

Hang on wait_for_server() on import, but not direct use

asked 2011-07-26 05:48:56 -0500

joschu gravatar image

updated 2014-01-28 17:10:07 -0500

ngrennan gravatar image

I have a function called with the lines

grip_r_client = actionlib.SimpleActionClient('r_gripper_controller/gripper_action', Pr2GripperCommandAction)
print "waiting for right gripper server"

Then I have a script, If I try to import, the program gets stuck at wait_for_server(). On the other hand, if I just copy those lines into, or if I do execfile(''), it works.

What's going on?

Edit: here's the full code. I would upload the package, but I don't have enough karma.

import roslib
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"

import roslib
import rospy,actionlib
import gripper
# OR ...

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.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2011-07-26 08:43:04 -0500

eitan gravatar image

In order for wait_for_server to work, ROS has to be initialized. When you import, python tries to run the 3 lines you pasted above since, I assume, they're not contained within any kind of function. So, if you're doing the import at the top of the file before a call to rospy.init_node the wait_for_server call will never return.

Normally, you'd wrap those three lines up in a function, import the file, and then call the function later after a call to rospy.init_node.

I'll admit that I'm guessing on a lot of the points I made since there's not enough information to be sure what's happening in the original post, but hopefully this helps.

edit flag offensive delete link more


Nope, I did initialize the node before the import. I edited my post to give more detail.
joschu gravatar image joschu  ( 2011-07-28 12:30:32 -0500 )edit
I think you are missing a rospy.init_node(...)
tpratkanis_wg gravatar image tpratkanis_wg  ( 2011-09-02 12:28:03 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2011-07-26 05:48:56 -0500

Seen: 504 times

Last updated: Jul 28 '11