CPython Signal Handler Check for SIGKILL

Antoine Pitrou solipsis at pitrou.net
Mon Jul 19 14:06:16 EDT 2010


Hello,

> I am not asking about the signals, I understand them,
> I am asking about the registration of the SIGNAL handler and how it knows
> that you are trying to register SIGKILL, you get an error like this.
> 
>  ./signal-catcher.py
> Traceback (most recent call last):
>   File "./signal-catcher.py", line 22, in <module>
>     signal.signal(signal.SIGKILL, signal_handler_kill)
> RuntimeError: (22, 'Invalid argument')

>>> import errno
>>> errno.errorcode[22]
'EINVAL'

EINVAL is the error returned by the standard POSIX signal() function
when trying to register a handler for SIGKILL. As the signal() man page
says:

[...]
       The signals SIGKILL and SIGSTOP cannot be caught or ignored.
[...]
ERRORS
       EINVAL signum is invalid.


So, in short, Python doesn't check SIGKILL by itself. It's just
forbidden by the underlying C standard library, and Python propagates
the error as a RuntimeError.

Regards

Antoine.





More information about the Python-list mailing list