Test for when a rospy publisher become available
I noticed that you must sleep for some amount of time before a rospy publisher actually starts to work. I was wondering if there is any way to test for this?
pub = rospy.Publisher('foo', bar)
pub.publish(bar('a')) # does not publish
rospy.sleep(1)
pub.publish(bar('b')) # actually does publish
Will publisher.get_num_connections() do this?
pub = rospy.Publisher('foo', bar)
print pub.get_num_connections() # prints 0
rospy.sleep(1)
print pub.get_num_connections() # prints 1
In my case it goes from 0 to 1, but will this simply increment by 1 in the general case? And if so, what if this node is started with several other nodes in a launch script? Is this safe to do and will it give me the guarantee I am looking for?
pub = rospy.Publisher('foo', bar)
num = pub.get_num_connections()
while not rospy.is_shutdown() and pub.get_num_connections() == num:
pass
pub.publish(bar())