When you want to exit a program written in python, the typical way to do it is to call sys.exit(status) like so:
For simple programs, this works great; as far as the python code is concerned, control leaves the interpreter right at the sys.exit method call. If you look under the hood, though, sys.exit is a little more interesting. It does not immediately call the libc function exit(), but instead raises a SystemExit exception. If nothing catches the exception, then the python interpreter catches it at the end, does not print a stack trace, and then calls exit.
import sys sys.exit(0)
There are situations in which you do not want to raise an exception to exit the program. The example I recently came across was debugging some of my python code in Oz. Oz is careful to clean up after itself, which means that on many exceptions it catches the exception, does some cleanup steps, and then re-raises the exception. In general this is a good thing to do, but sometimes when debugging I want to totally skip the cleanup steps so I can examine what went wrong.
Enter os._exit(). This function is a thin wrapper around the libc function exit(), so it does not raise an exception and leaves the program immediately. You would use it like:
import os os._exit(1)