In a previous answer a similar issue was addressed but solved in another manner, however the solution suggsted:
def cb_once(msg, subscriber):
#do processing here
subscriber.unregister()
sub_once = None
sub_once = rospy.Subscriber('my_topic,', MyType, cb_once, sub_once)
However since you the right hand side of the last line has to finish before equating to the left hand side, thus sub_once point to wrong place, hence in the cb_once, subscriber.unregister() can't work. Is there another way?
Many Thanks
Guy
Originally posted by Phuicy on ROS Answers with karma: 46 on 2012-10-23
Post score: 3
Original comments
Comment by Bill Smart on 2013-07-02:
When you say "can't work" do you mean "I don't think it works" or "I tried it and it doesn't work"? The callback isn't called by Subscriber, although (I think that) there's a small chance that it will fire before Subscriber returns (very small, probably).
Comment by Bill Smart on 2013-07-02:
You can always wrap the callback code in a try block if you're worried that it will fail.