topic을 처리할 때 시간이 걸리는데 그러면 바로 그 다음 topic를 처리하는지, 그때 들어온 topic을 처리하는지를 확인하기 위한 실습
#!/usr/bin/env python
import rospy
from std_msgs.msg import Int32
name = "sender"
pub_topic = "my_topic"
rospy.init_node(name)
pub = rospy.Publisher(pub_topic, Int32, queue_size=1)
rate = rospy.Rate(1000)
count = 1
while(pub.get_num_connections()==0):
continue
while not rospy.is_shutdown():
pub.publish(count)
count = count+1
rate.sleep()
#!/usr/bin/env python
import rospy
from std_msgs.msg import Int32
name = "receiver"
sub_topic = "my_topic"
def callback(msg):
rospy.loginfo("callback id being processed")
rospy.sleep(5)
print msg.data
rospy.init_node(name)
rospy.Subscriber(sub_topic, Int32, callback, queue_size=1)
rospy.spin()
<launch>
<node pkg="msg_send" type="sender_overflow.py" name="sender"/>
<node pkg="msg_send" type="receiver_overflow.py" name="receiver" output="screen"/>
</launch>
$ chmod +x receiver_overflow.py sender_overflow.py
$ roslaunch msg_send sr_overflow.launch