Gracefull application exit.

M.-A. Lemburg mal at egenix.com
Sat Jul 26 20:30:06 CEST 2008


On 2008-07-24 18:06, Robert Rawlins wrote:
> Chaps,
> 
>  
> 
> I'm looking to implement an exit/termination process for an application
> which can be triggered by A) a keyboard interrupt or B) termination of the
> application as a Daemon using a signal.
> 
>  
> 
> I have a whole bunch of tasks I want to perform as a cleanup before the
> application is terminated, cleaning files, database calls, closing open
> connections and a few other things.
> 
>  
> 
> I know we have:
> 
>  
> 
> # I'm the main application started method.
> 
> if __name__ == "__main__":
> 
>  
> 
> For starting an application, but do we have an equivalent methods for when
> an application is terminated which we can use to close down any current
> internal processes before the application exits?
> 
>  
> 
> I'd really love to have your thoughts and experience on gracefully killing
> an application.

Warp your whole application into a main() function and then use:

try:
     main()
finally:
     cleanup()

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Jul 25 2008)
 >>> Python/Zope Consulting and Support ...        http://www.egenix.com/
 >>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
 >>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________

:::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! ::::


    eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
     D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
            Registered at Amtsgericht Duesseldorf: HRB 46611



More information about the Python-list mailing list