Destructor?

Gabriel Rossetti gabriel.rossetti at mydeskfriend.com
Tue Apr 8 09:05:27 CEST 2008


Hello everyone,

we are writing an application that needs some cleanup to be done if the 
application is quit, normally (normal termination) or by a signal like 
SIGINT or SIGTERM. I know that the __del__ method exists, but unless I'm 
mistaken there is no guarantee as of when it will be called, and some 
objects may have already been released (at lease I've had trouble in the 
past accessing certain objects from inside __del__, probably since the 
parent class's __del__ has to be called first, then it's objects are 
already released by the time I need to do something with them). Another 
method would be to implement something using the signal module and have 
a callback that does all the cleanup when the app. is 
quit/terminated/interrupted and have all the child classes override that 
with their cleanup code.

What is the community's point of view on the subject?

Thanks,
Gabriel



More information about the Python-list mailing list