Please, who can explain why I get this error :
ValueError: invalid signal value
when trying to execute this test code, under Python 2.7.6 as well as under Python 3.3
import signal, os
def handler(signum, frame):
print('Signal handler called with signal', signum)
signal.signal(signal.CTRL_C_EVENT, handler)
You cannot register a signal handler for CTRL_C_EVENT
, because it is not supported.
Unfortunately, the Python docs on CTRL_C_EVENT don't really state that explicitly: When the docs say "the signal can only be used with os.kill
", they mean it literally, as in "really, all you can do with this signal is use it as in os.kill(pid, signal.CTRL_C_EVENT)
, so don't try registering a handler for it".
For some background, see Python issue 9524.
Should the behavior be better documented? Hell yes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With