On 9/22/06, Aahz <[EMAIL PROTECTED]> wrote:
> On Sat, Sep 23, 2006, Giovanni Bajo wrote:
> >
> > Did you actually read my posts where I have shown some legitimate use
> > cases of __del__ which can't be substituted with short and elegant
> > enough code?
>
> The question is whether those use cases are frequent enough -- especially
> for less-than-wizard programmers -- to warrant keeping __del__ around.
I still haven't seen one that can't be done pretty trivially with a
weakref. Perhaps the solution is to make doing cleanup-by-weakref
easier or more obvious? Something like this maybe:
import weakref
class GarbageDisposal:
def __init__(self):
self.refs = set()
def __call__(self, object, func, *args, **kw):
def cleanup(ref):
self.refs.remove(ref)
func(*args, **kw)
self.refs.add(weakref.ref(object, cleanup))
on_cleanup = GarbageDisposal()
class Wrapper:
def __init__(self, *args):
self.handle = CAPI.init(*args)
on_cleanup(self, CAPI.close, self.handle)
def foo(self):
CAPI.foo(self.handle)
-bob
_______________________________________________
Python-3000 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe:
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com