ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

rospy.wait_for_message just hangs

asked 2018-08-07 10:59:43 -0500

Marc_Chen gravatar image

updated 2018-08-07 12:28:21 -0500

jayess gravatar image

there is no exception or anything, rospy.wait_for_message just hangs, and no result is returned, and no subsequent code is executed. running

rostopic echo /my_topic

is able to yield result. Someone can provide an example of how to use wait_fo_message?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2018-08-07 12:26:53 -0500

jayess gravatar image

updated 2019-07-09 16:05:54 -0500

Take a look at the documentation. Or, if you look at the source for the wait_for_message function, you'll see that you can specifiy a timeout. If that timeout is exceeded then an exception will be raised (I removed the parts that aren't necessary for the question)

def wait_for_message(topic, topic_type, timeout=None):

    @param timeout: timeout time in seconds
    @type  timeout: double
    @raise ROSException: if specified timeout is exceeded

So, just call the function like this

rospy.wait_for_message(my_topic, MyMessage, my_timeout)

and if my_timeout is exceeded a ROSException will be raised.

edit flag offensive delete link more


No need to go to the source, just read the documentation.

gvdhoorn gravatar image gvdhoorn  ( 2018-08-07 13:48:34 -0500 )edit

answered 2019-07-09 15:34:45 -0500

rfn123 gravatar image

I had the same problem, using it like this:


The problem was that I missed a rospy.spin() in the whole Python script, because I did not intend to create a ROS node. However the missing rospy.spin was causing rospy not iterating through the message queues, thus waiting forever even if the topic actually publishes something.

edit flag offensive delete link more

Question Tools


Asked: 2018-08-07 10:59:43 -0500

Seen: 4,624 times

Last updated: Jul 09 '19