Handling kill signals
exarkun at intarweb.us
Tue Jun 10 22:59:20 CEST 2003
On Tue, Jun 10, 2003 at 04:54:44PM -0400, Gary Robinson wrote:
> 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?
You cannot. The KILL signal is uncatchable and unignorable in a POSIX
environment. Any well behaved system should first send another signal, such
as SIGHUP, before deciding that SIGKILL is required.
If it jams -- force it. If it breaks, it needed replacing anyway.
More information about the Python-list