Abnormal Interpreter Shutdown

K

k3xji

Hi all,

Is there anyway to detect abnormal interpreter shutdown like (closing
from task manager, power shutdown of the PC..etc)?

Regards,
 
T

Tim Golden

k3xji said:
Hi all,

Is there anyway to detect abnormal interpreter shutdown like (closing
from task manager, power shutdown of the PC..etc)?

"Task Manager" suggests you're using Windows, on which basis
you've got a few options open to you, but fundamentally if
someone pulls the plug on the PC you're not going to spot it.

Look at the SetConsoleCtrlHandler API[1], which is available
in the pywin32 package, and the WMI power events[2]. I don't
know exactly how far each one will go if someone stomps on
your process, but they're definitely worth looking at.

TJG

[1] http://msdn.microsoft.com/en-us/library/ms686016(VS.85).aspx
[2] http://msdn.microsoft.com/en-us/library/aa394362(VS.85).aspx
 
T

Terry Reedy

Tim said:
k3xji said:
Hi all,

Is there anyway to detect abnormal interpreter shutdown like (closing
from task manager, power shutdown of the PC..etc)?

"Task Manager" suggests you're using Windows, on which basis
you've got a few options open to you, but fundamentally if
someone pulls the plug on the PC you're not going to spot it.

Look at the SetConsoleCtrlHandler API[1], which is available
in the pywin32 package, and the WMI power events[2]. I don't
know exactly how far each one will go if someone stomps on
your process, but they're definitely worth looking at.

TJG

[1] http://msdn.microsoft.com/en-us/library/ms686016(VS.85).aspx
[2] http://msdn.microsoft.com/en-us/library/aa394362(VS.85).aspx

If you mean detecting abnormal shutdown after the fact, as opposed to
catching it while happening, you could create an empty temp file when
the program starts and delete it upon normal termination.
 
K

k3xji

If you mean detecting abnormal shutdown after the fact, as opposed to
catching it while happening, you could create an empty temp file when
the program starts and delete it upon normal termination.

I have a server application, and I want to take some actions *before*
the shutdown. I assumed to have some kind of event or Exception being
raised when Interpreter is closed abnormally.

I will take a look at the links.

Thanks a lot.
 
K

k3xji

I think what I am looking for is SetConsoleCtrlHandler(..) which
receives signals for CTRL+C and system shutdown. I don't want to take
the power outage into account because as far as I can see there is no
portable/simple/reliable way to accomplish that. So, thanks for the
tip again.

So what is the equivalent of this API in Linux? How can I accomplish
the same behavior for Linux?

Thanks a lot.
 
G

Gabriel Genellina

I think what I am looking for is SetConsoleCtrlHandler(..) which
receives signals for CTRL+C and system shutdown. I don't want to take
the power outage into account because as far as I can see there is no
portable/simple/reliable way to accomplish that. So, thanks for the
tip again.

So what is the equivalent of this API in Linux? How can I accomplish
the same behavior for Linux?

Using signal - see http://linux.die.net/man/7/signal and signal(2)
 
T

Terry Reedy

k3xji said:
I think what I am looking for is SetConsoleCtrlHandler(..) which
receives signals for CTRL+C and system shutdown. I don't want to take
the power outage into account because as far as I can see there is no
portable/simple/reliable way to accomplish that. So, thanks for the
tip again.

If your hardware is connected to a UPS (uninterruptable power supply aka
battery backup) that signals the OS when power has gone and it has
switched to the battery, you should be able to respond to that also.
 

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,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top