473,287 Members | 1,613 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,287 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 1539
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) ...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
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...
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)...

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.