Python Shutdown hook comp.lang.python. My comp.lang.python post.....
http://123maza.com/65/orange458/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Shutdown hook
On 15 Nov 2005 14:45:27 -0800, Steve <[EMAIL PROTECTED]> wrote: > Does any one know if python has the ability to run a shutdown hook. Look at the "atexit" module. barbet (~)$ pydoc atexit.register Help on function register in atexit: atexit.register = register(func, *targs, **kargs) register a function to be executed upon normal program termination func - function to be called at exit targs - optional arguments to pass to func kargs - optional keyword arguments to pass to func -- Steve Juranich Tucson, AZ USA -- http://mail.python.org/mailman/listinfo/python-list
Re: Shutdown hook
great. It's a good idea. -- http://mail.python.org/mailman/listinfo/python-list
Re: Shutdown hook
Lawrence Oluyede wrote: > Il 2005-11-15, Ben Finney <[EMAIL PROTECTED]> ha > scritto: >> Steve <[EMAIL PROTECTED]> 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 think using atexit module - > http://docs.python.org/lib/module-atexit.html is cleaner > Correct, although this won't catch all cases where a program is exiting. For example, on Windows, if you use Ctrl+C to terminate a program the atexit function *is* called, but if you use Ctrl+Break the atexit function is not called unless you install a suitable signal handler: import signal def sigbreak(signum, frame): sys.exit("***break") signal.signal(signal.SIGBREAK, sigbreak) Even then there are still other ways to terminate a process which will not be caught. -- http://mail.python.org/mailman/listinfo/python-list
Re: Shutdown hook
Il 2005-11-15, Ben Finney <[EMAIL PROTECTED]> ha scritto: > Steve <[EMAIL PROTECTED]> 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 think using atexit module - http://docs.python.org/lib/module-atexit.html is cleaner -- Lawrence - http://www.oluyede.org/blog "Anyone can freely use whatever he wants but the light at the end of the tunnel for most of his problems is Python" -- http://mail.python.org/mailman/listinfo/python-list
Re: Shutdown hook
Thanks do appreciate it -- Lisp Programming - You don't know what your missing ... == Help Send Laurie to Veterinary School http://www.sendlaurietovetschool.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Shutdown hook
Steve <[EMAIL PROTECTED]> 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 -- http://mail.python.org/mailman/listinfo/python-list
Shutdown hook
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)); -- http://mail.python.org/mailman/listinfo/python-list