Bruno Desthuilliers wrote:
> Mathias Panzenboeck a écrit :
>
> About the lost weakref problem: in Python, methods are just tiny
> wrappers around the object, class and function created at lookup time
> (yes, on *each* lookup) (and WWAI, they are by the function object
> itself, which implements th
Mathias Panzenboeck a écrit :
About the lost weakref problem: in Python, methods are just tiny
wrappers around the object, class and function created at lookup time
(yes, on *each* lookup) (and WWAI, they are by the function object
itself, which implements the descriptor protocol).
> When I ch
On 10/8/07, Steven D'Aprano <[EMAIL PROTECTED]> wrote:
> On Mon, 08 Oct 2007 04:06:55 +, Michele Simionato wrote:
>
> > > Hmmm... I'm not sure I understand how a with statement is meant to
> > > replace class.__del__ in practice. It seems to me that the two things
> > > have different uses. wit
On Mon, 08 Oct 2007 04:06:55 +, Michele Simionato wrote:
> > Hmmm... I'm not sure I understand how a with statement is meant to
> > replace class.__del__ in practice. It seems to me that the two things
> > have different uses. with is useful when you create an object, do
> > something with it,
On Oct 7, 11:28 pm, Steven D'Aprano
<[EMAIL PROTECTED]> wrote:
> On Sun, 07 Oct 2007 12:55:29 -0700, Alex Martelli wrote:
> >> What should I do when my objects need to perform some special
> >> processing when they are freed, if I shouldn't use __del__?
>
> > The solid, reliable way is:
>
> > from
On Sun, 07 Oct 2007 12:55:29 -0700, Alex Martelli wrote:
>> What should I do when my objects need to perform some special
>> processing when they are freed, if I shouldn't use __del__?
>
> The solid, reliable way is:
>
> from __future__ import with_statement
>
> and use module contextlib from
Alex Martelli wrote:
> Mathias Panzenboeck <[EMAIL PROTECTED]> wrote:
>
>> Marc 'BlackJack' Rintsch wrote:
>>> ``del b`` just deletes the name `b`. It does not delete the object.
>>> There's still the name `_` bound to it in the interactive interpreter.
>>> `_` stays bound to the last non-`None`
Mathias Panzenboeck <[EMAIL PROTECTED]> wrote:
> Marc 'BlackJack' Rintsch wrote:
> > ``del b`` just deletes the name `b`. It does not delete the object.
> > There's still the name `_` bound to it in the interactive interpreter.
> > `_` stays bound to the last non-`None` result in the interpreter.
Mathias Panzenboeck <[EMAIL PROTECTED]> wrote:
...
> I only inserted them so I can see if the objects are really freed. How can
> I see that without a __del__ method?
You can use weakref.ref instances with finalizer functions - see the
long post I just made on this thread for a reasonably rich
Steven D'Aprano <[EMAIL PROTECTED]> wrote:
...
> Without __del__, what should I have done to test that my code was
> deleting objects and not leaking memory?
See module gc in the Python standard library.
> What should I do when my objects need to perform some special processing
> when they a
On Oct 7, 1:14 pm, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:
> On Sun, 07 Oct 2007 16:38:23 +, Michele Simionato wrote:
> > On Oct 7, 12:26 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
>
> >> Drop all those `__del__()` methods as they prevent the garbage
> >> coll
Mathias Panzenboeck wrote:
> Marc 'BlackJack' Rintsch wrote:
>> ``del b`` just deletes the name `b`. It does not delete the object.
>> There's still the name `_` bound to it in the interactive interpreter.
>> `_` stays bound to the last non-`None` result in the interpreter.
>
> Actually I have
On Sun, 07 Oct 2007 16:38:23 +, Michele Simionato wrote:
> On Oct 7, 12:26 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
>
>> Drop all those `__del__()` methods as they prevent the garbage
>> collector from collecting "cycles".
>
> I fully agree and I will add that __del__ methods
Marc 'BlackJack' Rintsch wrote:
> ``del b`` just deletes the name `b`. It does not delete the object.
> There's still the name `_` bound to it in the interactive interpreter.
> `_` stays bound to the last non-`None` result in the interpreter.
>
Actually I have the opposite problem. The referen
Marc 'BlackJack' Rintsch wrote:
> On Sun, 07 Oct 2007 16:51:33 +0200, Mathias Panzenboeck wrote:
>
>> import weakref
>>
>> class Wrapper(object):
>> def __init__(self,x):
>> self.x = weakref.ref(x)
>>
>> def __call__(self,*args,**kwargs):
>> x = self.x()
>>
On Oct 7, 12:26 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
> Drop all those `__del__()` methods as they prevent the garbage collector
> from collecting "cycles".
I fully agree and I will add that __del__ methods are always
a bad idea. Also notice that recently Raymond Hetting said in
On Sun, 07 Oct 2007 16:51:33 +0200, Mathias Panzenboeck wrote:
> import weakref
>
> class Wrapper(object):
> def __init__(self,x):
> self.x = weakref.ref(x)
>
> def __call__(self,*args,**kwargs):
> x = self.x()
> if x is None:
>
When I change the class Wrapper to following, the class Foo works:
class Wrapper(object):
def __init__(self,x):
self.func_name = x.func_name
self.x = weakref.ref(x.im_self)
def __call__(self,*args,**kwargs):
x = self.x()
18 matches
Mail list logo