On 9/23/06, Giovanni Bajo <[EMAIL PROTECTED]> wrote:
> Bob Ippolito wrote:
>
> > 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)
>
> Try with this:
>
> class Wrapper2:
>    def __init__(self, *args):
>         self.handle = CAPI.init(*args)
>
>    def foo(self):
>         CAPI.foo(self.handle)
>
>    def restart(self):
>         self.handle = CAPI.restart(self.handle)
>
>    def close(self):
>         CAPI.close(self.handle)
>         self.handle = None
>
>    def __del__(self):
>          if self.handle is not None:
>                 self.close()

I've never seen an API that works like that. Have you?

-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

Reply via email to