Destructor?

Gabriel Rossetti gabriel.rossetti at mydeskfriend.com
Tue Apr 8 03:50:52 EDT 2008


Matt Nordhoff wrote:
> Matt Nordhoff wrote:
>   
>> 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..
>>     
>
> Huh, I totally didn't know that atexit is only run on normal
> terminations. Oops. Never mind.
>   
Yes, and I just saw that windows (my app has to support Linux, Mac OS X 
and Windows) does not know about SIGINT and SIGTERM is apparently there 
for ANSI compatibility by an app has to explicitly raise it...every line 
of code I right I had windows more and more....



More information about the Python-list mailing list