Making a python cgi script to finish gracefully?

You can trap the exit signal with the signal module. Haven't tried this with mod_python though docs.python.org/library/signal.html Note in the docs: When a signal arrives during an I/O operation, it is possible that the I/O operation raises an exception after the signal handler returns. This is dependent on the underlying Unix system’s semantics regarding interrupted system calls You may need to catch I/O exceptions for the broken pipe and/or file write if you don't sys.

Exit from your handler.

You can trap the exit signal with the signal module. Haven't tried this with mod_python though. docs.python.org/library/signal.html Note in the docs: When a signal arrives during an I/O operation, it is possible that the I/O operation raises an exception after the signal handler returns.

This is dependent on the underlying Unix system’s semantics regarding interrupted system calls. You may need to catch I/O exceptions for the broken pipe and/or file write if you don't sys. Exit from your handler.

Mod_python wouldn't be involved here, if the OP is running the script as a CGI script. – David Zaslavsky May 20 '09 at 8:37.

The script is probably not killed silently; you just don't see the exception which python throws. I suggest to wrap the whole script in try-except and write any exception to a log file. This way, you can see what really happens.

The logging module is your friend.

When the client closes -- and the socket eventually times out -- you should get an I/O error of some kind. – S. Lott May 20 '09 at 11:07.

You may be able to use the atexit module. docs.python.org/library/atexit.html From the documentation: The atexit module defines a single function to register cleanup functions. Functions thus registered are automatically executed upon normal interpreter termination.

Note: the functions registered via this module are not called when the program is killed by a signal, when a Python fatal internal error is detected, or when os. _exit() is called. This is an alternate interface to the functionality provided by the sys.

Exitfunc variable.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions