Handling kill signals
ulope at gmx.de
Wed Jun 11 03:09:05 CEST 2003
"Gary Robinson" <grobinson at transpose.com> schrieb im Newsbeitrag
news:mailman.1055278547.15020.python-list at python.org...
> 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.)
Though i get no error when trying to catch it (expectedly) doesn't work.
But to solve your problem you might want to catch the SIGTERM since IMHO its
sent by all linux(-alike) systems on shutdown before the SIGKILL signal...
More information about the Python-list