del behavior 2
MRAB
google at mrabarnett.plus.com
Wed Jan 7 14:55:40 EST 2009
Eric Snow wrote:
> I was reading in the documentation about __del__ and have a couple of
> questions. Here is what I was looking at:
>
> http://docs.python.org/reference/datamodel.html#object.__del__
>
> My second question is about the following:
>
> "It is not guaranteed that __del__() methods are called for objects
> that still exist when the interpreter exits."
>
> I understand that and have seen it too. That's fine. But how do any
> of you deal with things that are left open because you did not get a
> chance to close them? How do you clean up after the fact? Do you
> simply keep track externally the things that need to be cleaned up if
> __del__ doesn't get a chance? Any ideas? Thanks
>
There's the 'with' statement and try...finally.
More information about the Python-list
mailing list