This exception is raised by the sys.exit function. When it is not handled, the Python interpreter exits; no stack traceback is printed. If the associated value is a plain integer, it specifies the system exit status (passed to C’s exit() function); if it is None, the exit status is zero; if it has another type (such as a string), the object’s value is printed and the exit status is one.
Instances have an attribute code which is set to the proposed exit status or error message (defaulting to None). Also, this exception derives directly from Exception and not StandardError, since it is not technically an error.
A call to sys.exit is translated into an exception so that clean-up handlers (finally clauses of try statements) can be executed, and so that a debugger can execute a script without running the risk of losing control. The os._exit function can be used if it is absolutely positively necessary to exit immediately (for example, in the child process after a call to os.fork).