It is __del__ calling twice for some instances?

Duncan Booth duncan.booth at invalid.invalid
Wed Aug 16 15:26:24 EDT 2006


Max Yuzhakov wrote:

> It is correct behaviour for python to call __del__ on some
> identity of a class object more than once?

Not with the code which you gave as an example, but in the general case 
yes, the only guarantee that Python gives about the __del__ method on an 
instance is that it will be called zero, one or more than one times during 
the run of the program. In practice there are various situations where 
__del__ will not be called, but it is only called multiple times if you 
resurrect the object during a call to __del__.

The output from your stat function could, of course, also be generated by 
creating and destroying lots of foo objects in another thread. If a foo was 
both created and destroyed between the first two print statements, and 
another one was created and destroyed in the middle of the evaluation of 
the last print statement then you could see the output you described 
without any multiple __del__ calls in the same object.

You should post a working code sample which generates your output if you 
want a more useful answer.




More information about the Python-list mailing list