class ClassB:

    def __call__(self, obj):
        print('ClassB object %d is called because obj %d is being destroyed' % (
            id(self), id(obj)))
using python WeakSet to enable a callback functionality