Writing to log file when script is killed

H

Harlin Seritt

I am looking for a way for my script to write to a log file saying
something like this:

I was killed at time.asctime()

I would like to be able to do this if/when the script is killed by
means rather than my own. How in the world would I accomplish this?

Thanks,

Harlin
 
H

Heiko Wundram

Am Samstag, 30. April 2005 14:26 schrieb (e-mail address removed):
If you run on unix you can use the signal module to intercept a kill -
see http://docs.python.org/lib/node368.html for a quick example

You cannot intercept a kill (that's the whole meaning of SIGKILL, rather than
SIGTERM)... Read up on UNIX signal handling.

But, for the rest: you could intercept SIGTERM, log a message, and raise a
SystemExit exception. That should do the trick.

--
--- Heiko.
see you at: http://www.stud.mh-hannover.de/~hwundram/wordpress/

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQBCc+pdf0bpgh6uVAMRAvT1AJ93WHff1LJx69T9Q+bgq4SqH3QEDgCeL5Sf
E+irmSUUFIEnR1ffhN3sMHQ=
=BUva
-----END PGP SIGNATURE-----
 
M

Miki Tebeka

Hello Heiko,
Am Samstag, 30. April 2005 14:26 schrieb (e-mail address removed):

You cannot intercept a kill (that's the whole meaning of SIGKILL, rather than
SIGTERM)... Read up on UNIX signal handling.

But, for the rest: you could intercept SIGTERM, log a message, and raise a
SystemExit exception. That should do the trick.
You can also use "register" from "atexit" module.

Bye.
--
------------------------------------------------------------------------
Miki Tebeka <[email protected]>
http://tebeka.bizhat.com
The only difference between children and adults is the price of the toys

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (Cygwin)

iD8DBQFCdOdl8jAdENsUuJsRAvADAJsHpeJUQYlqD6MbJPkaq5AsKZfw2ACfWDLS
nVcuW6ePqXr0jZqlJK34o/c=
=8Z9o
-----END PGP SIGNATURE-----
 
M

Michael Hoffman

Ok, I was sloppy - I meant the regular kill, not the -9 version...

You're still being sloppy. ;) The "-9 version" is called SIGKILL, hence
the confusion (actually I doubt anyone is confused).

What you mean is SIGTERM. Call it that and you will be safe even from
the most demanding of pedants.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,951
Messages
2,570,113
Members
46,699
Latest member
Abigail89S

Latest Threads

Top