0
$\begingroup$

Rosanswers logo

This just came up in an assignment that I'm grading, and I can't figure out why it works. In the constructor of a class, there is:

self.sub = rospy.Subscriber('/odom', Odometry, self.seek_goal)

followed immediately by

self.sub = rospy.Subscriber('/base_scan', LaserScan, self.laser_agg)

My understanding is that, when self.sub is reassigned, the original Subscriber should go out of scope, get destroyed, and get garbage-collected. However, both callbacks seem to run happily for the duration of the node's existence.

Any Python gurus out there with any insight? I could guess about the object not getting reaped, but it should still go out of scope (and get destroyed), right?


Originally posted by Bill Smart on ROS Answers with karma: 1263 on 2012-11-16

Post score: 1

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

After looking at rospy's source code, it looks like no __del__ method is implemented for subscribers. That means, topics are just not cleaned up when a subscriber object is destroyed. The user needs to manually unregister topics.

I'm not sure if this was intended behavior but I would consider filing an enhancement ticket.


Originally posted by Lorenz with karma: 22731 on 2012-11-18

This answer was ACCEPTED on the original site

Post score: 3


Original comments

Comment by joq on 2012-11-24:
I recently noticed a similar issue with rospy service advertisements.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.