![](https://secure.gravatar.com/avatar/dc1e44d52927c340c4f644a5d909c096.jpg?s=120&d=mm&r=g)
April 11, 2016
2:22 p.m.
Currently, if I want to have weakref.finalize call an object's cleanup method, I have to do something like: class foo: _finalizer = None def __init__(self): self._finalizer = weakref.finalize(self, foo._cleanup, weakref.WeakMethod(self.cleanup)) def __del__(self): self.cleanup() @classmethod def _cleanup(cls, func): func()() def cleanup(self): if self._finalizer is not None: self._finalizer.detach() print('cleaning up') It wouldn't be difficult to have weakref.finalize automatically handle the conversion to WeakMethod and automatically attempt to dereference then call the function passed in.
3233
Age (days ago)
3233
Last active (days ago)
0 comments
1 participants
participants (1)
-
Matthew Stoltenberg