Home > Article > Backend Development > How to stop running python
Python is a program that interprets and runs. If the program enters an infinite loop or other exceptions, the program will not end normally. Although the python program will not cause the system to enter an abnormal state that is difficult to recover like the exe program, it will make the python interpreter unable to continue working, especially when using the command line mode. Then we need to consider the termination of the python program.
Method 1: Use sys.exit(0) to terminate the program normally. As you can see from the figure, the shell operation will not be affected after the program terminates.
Method 2: Use os._exit(0) to close the entire shell. As you can see from the picture, the entire shell restarts after calling sys._exit(0) (RESTART Shell).
Related recommendations: "Python Video Tutorial"
Method 3: Use the Ctrl C shortcut key to forcefully terminate program execution. You can It can be seen that the order is terminated by "KeyboardInterrupt" (keyboard interrupt), and it does not affect the continued execution of the shell.
Method 4: The simplest and crudest way to terminate the program is to click the "x" in the upper right corner of the shell. The entire shell is terminated, and the program is terminated decisively!
The above is the detailed content of How to stop running python. For more information, please follow other related articles on the PHP Chinese website!