One can send a KeyboardInterrupt
to a running python program by pressing Ctrl-c
. Is there a way to bind other keyboard combinations to custom python exceptions?
Specifically, I usually stop my program by pressing ctrl+c
and then it handles the exception and exits cleanly. However, occasionally I want to stop it such that it performs a different cleanup procedure on exit. My program usually runs for several days without stopping so when I am launching it I do not know which way I want to use to kill it.
In a nutshell, I want to execute different cleanup procedures, based on some user input during runtime. My program is very computationally intensive so I would prefer a solution where I can send an exception rather than poll for user input.