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)); 10 10557
Steve <st*********@gmail.com> 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
Thanks do appreciate it
--
Lisp Programming - You don't know what your missing ...
======================================
Help Send Laurie to Veterinary School http://www.sendlaurietovetschool.com
Il 2005-11-15, Ben Finney <bi****************@benfinney.id.au> ha scritto: Steve <st*********@gmail.com> 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"
Il 2005-11-15, Ben Finney <bi****************@benfinney.id.au> ha scritto: Steve <st*********@gmail.com> 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"
Lawrence Oluyede wrote: Il 2005-11-15, Ben Finney <bi****************@benfinney.id.au> ha scritto: Steve <st*********@gmail.com> 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.
Lawrence Oluyede wrote: Il 2005-11-15, Ben Finney <bi****************@benfinney.id.au> ha scritto: Steve <st*********@gmail.com> 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.
On 15 Nov 2005 14:45:27 -0800, Steve <st*********@gmail.com> 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
On 15 Nov 2005 14:45:27 -0800, Steve <st*********@gmail.com> 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Jonathan Heath |
last post by:
Hi all,
I have created an ASP script that enters data into an Access Database.
My problem is that I'd like this script to run when the computer is shutdown
or the user logs off.
I think...
|
by: Allan Bredahl |
last post by:
Hi All
I am trying to construct an application that is able to cancel a machine
shutdown, reboot or logoff. And after performing some stuff to perform the
original shutdown order :...
|
by: Senthil |
last post by:
Hi,
I would like to know the code for reboot and shutdown windows xp
professional using VB.Net.
thanx
Senthil
|
by: Chris Tanger |
last post by:
Context:
C#
System.Net.Sockets
Socket created with constructor prarmeters Internetwork, Stream and TCP
everything else is left at the default parameters and options except linger
may be changed...
|
by: Brian Worth |
last post by:
I have just upgraded from VB 4.0 to VB .NET 2002. One program under VB 4.0
was able to shut down or restart the (windows XP) machine using a series of
API calls. (Getlasterror, GetCurrentProcess,...
| |
by: yaron |
last post by:
Hi,
I am developing an infrastructure dll in c#.
my dll can be use by all kind of application containers win/web/console.
how do i implement a shutdown hook which will be called when the user...
|
by: zeng.hui.stephen |
last post by:
I download the demo
http://msdn.microsoft.com/msdnmag/issues/02/10/cuttingedge/. I
inherite the demo, and write my code.
I want to use Hook to monitor C++ Edit change. I use a C# form...
|
by: Phil Tusa |
last post by:
Greetings to all ....
I have a need to issue a shutdown and/or Restart Windows XP inside my
application. Any help or example code would be appreciated!
--
Phil
|
by: lawbaal |
last post by:
Here I got 3 computers A,B and C, they are all with windows xp pro running.
Above all: I've open the remote force shutdown permission for guest account in all of these three computer. But....
...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |