from b import B class A(object): def __init__(self, b): self.b = B() def __del__(self): self.b.cleanup()