In this tutorial, we will introduce 4 methods to stop running python script.
Method 1: Ctrl+c
If you are running python script by terminal, you can press Ctrl+c to stop a running python script.
Method 2: Use exit() function in python script.
Method 3: Use sys.exit() function
Here is an example:
import sys sys.exit()
Method 4: Use os._exit(0) function
Here is an example:
import os os._exit(0)