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 the
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 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. with is useful
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
Hi.
I have a problem with weak refs and bound methods. The best explanation for the
problem is a short bit of code. I have the three classes Wrapper, Foo and Bar:
import weakref
class Wrapper(object):
def __init__(self,x):
self.x = weakref.ref(x)
def
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()
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:
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
this
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()
if x is
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 reference
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 are always
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 the
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
collector from
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 are
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 and
.
Actually I have the opposite problem. The reference (to the bound method)
gets lost but it shouldn't!
weakrefs to bound methods require some subtlety, see
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81253 (or what
I believe is the better treatment of this recipe in the printed edition
in the interpreter.
Actually I have the opposite problem. The reference (to the bound method)
gets lost but it shouldn't!
weakrefs to bound methods require some subtlety, see
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81253 (or what
I believe is the better treatment of this recipe
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 the
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 __future__
19 matches
Mail list logo