469,955 Members | 2,310 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,955 developers. It's quick & easy.

Re: Gracefull application exit.

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:

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

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.
"""

TJG

Jul 24 '08 #1
0 1536

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Guinness Mann | last post: by
4 posts views Thread by Bob Day | last post: by
2 posts views Thread by Susan Baker | last post: by
1 post views Thread by =?Utf-8?B?VGFvZ2U=?= | last post: by
reply views Thread by Robert Rawlins | last post: by
reply views Thread by M.-A. Lemburg | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.