473,320 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Writing to log file when script is killed

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

Jul 19 '05 #1
5 1540
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

Jul 19 '05 #2
Am Samstag, 30. April 2005 14:26 schrieb wi******@hotmail.com:
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+bgq4 SqH3QEDgCeL5Sf
E+irmSUUFIEnR1ffhN3sMHQ=
=BUva
-----END PGP SIGNATURE-----

Jul 19 '05 #3
Hello Heiko,
Am Samstag, 30. April 2005 14:26 schrieb wi******@hotmail.com:
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.

You can also use "register" from "atexit" module.

Bye.
--
------------------------------------------------------------------------
Miki Tebeka <mi*********@zoran.com>
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)

iD8DBQFCdOdl8jAdENsUuJsRAvADAJsHpeJUQYlqD6MbJPkaq5 AsKZfw2ACfWDLS
nVcuW6ePqXr0jZqlJK34o/c=
=8Z9o
-----END PGP SIGNATURE-----

Jul 19 '05 #4
Ok, I was sloppy - I meant the regular kill, not the -9 version...

Jul 19 '05 #5
wi******@hotmail.com wrote:
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.
--
Michael Hoffman
Jul 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Iceman | last post by:
I am logging things to a file but when I kill the app and restart it, all the other logging is gone. How can I prevent this form happening?
2
by: jakeruston | last post by:
Hi, I have coded this and it is coming up with hundreds of errors. What is wrong with this anyway? #include <iostream> #include <string> using namespace std; using std::cout;
3
by: Lawrence D'Oliveiro | last post by:
Дамјан Георгиевски wrote: A Linux-specific solution is prctl(2).
2
by: ksrashmi | last post by:
Hi , does jar file loaidng will consume the jvm memory ? I have to run the cronjobs for some of the java files . so i have writen the .sh file ( linux server) ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shllpp 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.