I wrote a program in IDLE to tokenize text files and it starts to tokeniza 349 text files! How can I stop it? How can I stop a running Python program?
To stop a python script using the keyboard: Ctrl
+ C
To stop it using code (This has worked for me on Python 3) :
import os
os._exit(0)
you can also use:
import sys
sys.exit()
or:
exit()
or:
raise SystemExit
To stop your program, just press Control + C.
Control+D works for me on Windows 10. Also, putting exit()
at the end also works.
exit() will kill the Kernel if you're in Jupyter Notebook so it's not a good idea. raise
command will stop the program.
If you are working with Spyder, use CTRL + . (DOT) and you will restart the kernel, also you will stop the program.
Ctrl + C
.exit()
, you can do it.pkill -f name-of-the-python-script
.