I wrote a little script that does something extremely time-consuming in Python and I included a signal handling module that listens for SIGINT, SIGQUIT and SIGINFO, printing the status when either SIGQUIT or SIGINFO are inputted by the user and aborting the program when SIGINT(CTRL-C) is entered. The code is EXTREMELY sloppy, because i hacked it down in a few minutes and stole some foreign code - dont worry, ill clean it up as soon as I(or rather, you, because I'm stuck) found the bug:
def setup_signals(progress_bar):
import signal
import sys
def progress(*args):
print(progress_bar)
def killitwithfire(*args):
print("[x] User interrupted with CTRL-C. Aborting.")
sys.exit(0)
for sig in (signal.SIGINFO, signal.SIGQUIT):
signal.signal(sig, progress)
for sig in (signal.SIGINT,):
signal.signal(sig, killitwithfire)
print("Sig handlers built:\n Press Ctrl+T(BSD/OS X) or Ctrf+4(Linux) for progress.")
print("Press CTRL-C to abort.")
Now, the problem is that when CTRL-C is entered, the message in killitwithfire() - sorry for the bad reference - is printed, but it won't exit.
The code in which this is executed is inside a try/catch/ block. If that is the problem, how can I exit from within this signal handling module? If it is not the problem, then what is it?