What is the difference between Ctrl-C and SIGINT?
^C
sends a SIGINT
to all the processes in the foreground process group. To do the equivalent with kill
, you should send the signal to the process group (OS-level concept):
kill -SIGINT -<pid>
or to the job (shell-level concept, the pipeline ended with &
):
kill -SIGINT %
As described here :
Python installs a small number of signal handlers by default: SIGPIPE is ignored (so write errors on pipes and sockets can be reported as ordinary Python exceptions) and SIGINT is translated into a KeyboardInterrupt exception. All of these can be overridden.
so, the behaviour should be the same between sending a SIGINT and a Ctrl + c.
But, you have to be carefull with the KeyboardInterrupt
, if somewhere in your code you've got a
try: ...except: # notice the lack of exception class pass
this will "eat" the KeyboardInterrupt exception.