rospy.wait_for_message is unable to subscribe to a message
rospy.wait_for_message can receive one message from topic. It will create a new subscription to the topic, receive one message, then unsubscribe. But when I try to use it, the function can't work at all. For example,
roscore &
rostopic pub -r 1 /data std_msgs/Float32 2.0
the use this function to subscribe once:
import rospy
from std_msgs.msg import Float32
rospy.wait_for_message('/data', Float32)
It will be stuck here and there is no response at all. But if we subscribe directly
rostopic echo /data
It can work. What's the matter with this function? And I try to test it on different computers and ROS version, the result is the same.