Killing Python: Exiting Without Using SystemExit
Usually in python you exit a script programmatically by raising SystemExit or calling sys.exit. Both methods send an exception hurtling up the call stack, allowing every level of your program to execute finally statements and exit cleanly.
This behaviour changes if you throw SystemExit in a multithreaded application: it kills the calling thread instead. If the calling thread is not the main thread the application will just keep ticking along. Fine in most cases, but sometimes you just need to make the application quit.
To achieve this, you need to call:
os._exit()with an error code of your choice.