problem using signal module

Ignacio Vazquez-Abrams ignacio at openservices.net
Fri Aug 24 05:32:12 EDT 2001


On 24 Aug 2001, Ken Guest wrote:

> Using Python 1.52 for hysterical raisens, I'm trying to
> set up a handler to intercept the KILL signal on a RedHat Linux
> box.
>
> In the code I have:
>
> import signal
>
> def handler(signo, frame):
>         print signo
>
> if __name__ == '__main__':
>         port = 8000
> 	#straight from the Python Standard Library book...
>         signal.signal(signal.SIGKILL, handler)
>
> But this raises the following exception:
>
>   File "./compassxmlrpcserver.py", line 128, in ?
>     signal.signal(signal.SIGKILL, handler)
> RuntimeError: (22, 'Invalid argument')
>
>
> Anyone know what I'm doing wrong?
>
> k.

It's really simple: you can't catch SIGKILL. Period. You might want to try
using SIGTERM instead. SIGTERM is the normal 'kill -15' (-15 is the default),
and SIGKILL is 'kill -9', which immediately stop execution of a program.

-- 
Ignacio Vazquez-Abrams  <ignacio at openservices.net>






More information about the Python-list mailing list