When python process was killed, we will not get KeyboardInterrupt. But we can instead catch SIGTERM sent by kill command.
List of signal is available in POSIX Signals. Note that SIGKILL cannot be caught.
When I use signal.SIGTERM I got KeyboardInterrupt, but when I changed it to signal.SIGINT it works like expected.
Could you explain this to me please?
It depends on how you kill the process.
If you use Ctrl-C, and catch SIGINT, then that might be the case that you got what you expected.
But if you use kill $PID, this might give you SIGTERM instead.