Re: Using weakrefs instead of __del__

2005-04-07 Thread Greg Ewing
Rhamphoryncus wrote: class RealFoo: refs = set() def __init__(self, front): self.refs.add(weakref.ref(front, self.cleanup)) def blah(self): print "Blah!" def cleanup(self, ref): print "Doing cleanup" self.refs.remove(ref) That won't work, because the bound method you're usin

Using weakrefs instead of __del__

2005-04-06 Thread Rhamphoryncus
I know __del__ can't be relied on to do cleanup, so I'm thinking of using a globally reachable weakref to do the job, like so: import weakref class Foo: def __init__(self, *args, **kwargs): self.__realfoo = RealFoo(self, *args, **kwargs) def blah(self): return self.__realfoo.blah() c