[Python-3000] Removing __del__

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Sat Sep 23 18:34:20 CEST 2006


"Giovanni Bajo" <rasky at develer.com> writes:

> 1) There's a way to destruct the handle BEFORE __del__ is called,
> which would require killing the weakref / deregistering the
> finalization hook.

Weakrefs should have a method which runs their callback and
unregisters them.

> 2) The objects required in the destructor can be mutated / changed
> during the lifetime of the instance. For instance, a class that
> wraps Win32 FindFirstFirst/FindFirstNext and support transparent
> directory recursion needs something similar.

Listing files with transparent directory recursion can be implemented
in terms of listing files of a given directory, such that a finalizer
is only used with the low level object.

> Another example is a class which creates named temporary files
> and needs to remove them on finalization. It might need to create
> several different temporary files (say, self.handle is the filename
> in that case)[1], so the filename needed in the destructor changes
> during the lifetime of the instance.

Again: move the finalizer to a single temporary file object, and refer
to such object instead of a raw handle.

-- 
   __("<         Marcin Kowalczyk
   \__/       qrczak at knm.org.pl
    ^^     http://qrnik.knm.org.pl/~qrczak/


More information about the Python-3000 mailing list