Python: exit

Python has 3 kinds of exit.


sys.exit() terminates the process. This is useful when we execute Python script file. In Python, return is available only in functions. So when we stop the execution in the middle of the file, we must use sys.exit().

sys.exit() can take one argument as the exit status.

sys.exit() internally execute raise SystemExit().


fork() によって生成された子プロセスのなかで実行するもので、 C言語の _exit() を実行します。


Terminates Python interactive shell. Even if we write this in the script file and execute it like python, the program doesn’t end not like sys.exit().