Home  >  Article  >  Backend Development  >  How to stop running python

How to stop running python

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼Original
2019-06-13 14:27:3521096browse

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.

How to stop running python

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.

How to stop running python

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"

How to stop running python

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.

How to stop running python

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!

How to stop running python

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn