By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,712 Members | 1,362 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,712 IT Pros & Developers. It's quick & easy.

Re: Gracefull application exit.

P: n/a
Robert Rawlins wrote:
Im 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?

Id really love to have your thoughts and experience on gracefully
killing an application.
You want to look at the atexit module:

but mind the caveats:

Note: the functions registered via this module are not
called when the program is killed by a signal, when a
Python fatal internal error is detected, or when
os._exit() is called.


Jul 24 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.