Python Shutdown hook comp.lang.python

My comp.lang.python post.....

Does any one know if python has the ability to run a shutdown hook.

For example you set a method to run when the python process is shutting
down, like it recieved a kill signal?

Basically looking for an effect like the following java code.
Runtime.getRuntime().addShutdownHook(new Thread(this));

Reply

2. Ben Finney
Nov 15, 5:55 pm show options
Newsgroups: comp.lang.python
From: Ben Finney - Find messages by this author
Date: Wed, 16 Nov 2005 09:55:17 +1100 (EST)
Local: Tues, Nov 15 2005 5:55 pm
Subject: Re: Shutdown hook

Steve wrote:
> Does any one know if python has the ability to run a shutdown hook.

When the Python runtime system wants to exit, it raises a SystemExit
exception.

Catch that exception at the top level of your code, and do whatever
you like. (It might be polite to actually exit at some point, of
course. sys.exit(exitcode) will do so -- raising another SystemExit
exception.)

--
\ "I took it easy today. I just pretty much layed around in my |
`\ underwear all day. ... Got kicked out of quite a few places, |
_o__) though." -- Bug-Eyed Earl, _Red Meat_ |
Ben Finney

Comments

Popular posts from this blog

Vim vi how to reload a file your editing