This is specifically for Windows, I don't have this issue on linux based systems.
So, I have a program that creates subprocesses when running it.
These subprocesses will terminate correctly if the program exits normally, or even with exceptions or ctrl+c event, by using try
and KeyboardInterrupt
and finally
in if __name__ == '__main__':
However, if I kill the program in the middle, I'm talking about killing it in PyCharm
, using the STOP
button. Those subprocesses will not terminate. I'm not exactly sure what signal this STOP
button sends on Windows.
I tried signal handling using signal.signal(signal.SIGTERM, handler)
. It doesn't work, I have tried SIGTERM
, SIGINT
, (SIGKILL
, CTRL_C_EVENT
, CTRL_BREAK_EVENT
don't work in signal handler. ). None of them works. I have also read this post: How to handle the signal in python on windows machine
How can I gracefully exit in this scenario? This STOP
button in PyCharm scenario.