Destructor?

Matt Nordhoff mnordhoff at mattnordhoff.com
Tue Apr 8 03:27:26 EDT 2008


Gabriel Rossetti wrote:
> 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

atexit? <http://docs.python.org/lib/module-atexit.html>

If it's only small things, there's try...finally, of course..
-- 



More information about the Python-list mailing list