Handling kill signals

Gary Robinson grobinson at transpose.com
Tue Jun 10 16:54:44 EDT 2003


For a daemon I'm writing, it would be very good if I could handle a kill
signal sent out by the operating system during shutdown.

But when I try to set up a handler, python rejects it:

>>>> import signal
>>>> def x(parm1, parm2):
> ...     pass
> ... 
>>>> signal.signal(signal.SIGKILL, x)
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> RuntimeError: (22, 'Invalid argument')
>>>> signal.signal(signal.SIGHUP, x)
> 0
>>>> 

IOW, signal.signal accepts SIGHUP but not SIGKILL. How can I get it to
accept SIGKILL?

Or is there some other way I can enable my script to perform some cleanup
when it's killed? 

(A handler assigned with atexit.register() doesn't seem to get called when
the script is killed by the OS during shutdown.)

Many thanks in advance for any help anyone can give.

--Gary

-- 
<http://ThisURLEnablesEmailToGetThroughOverzealousSpamFilters.org>

Gary Robinson
CEO
Transpose, LLC
grobinson at transpose.com
207-942-3463
http://www.transpose.com
http://radio.weblogs.com/0101454







More information about the Python-list mailing list