How to stop/terminate a python script from running?

后端 未结 16 1748
-上瘾入骨i
-上瘾入骨i 2020-12-02 13:46

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?

相关标签:
16条回答
  • 2020-12-02 14:39

    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
    
    0 讨论(0)
  • 2020-12-02 14:41

    To stop your program, just press Control + C.

    0 讨论(0)
  • 2020-12-02 14:41

    Control+D works for me on Windows 10. Also, putting exit() at the end also works.

    0 讨论(0)
  • 2020-12-02 14:45

    exit() will kill the Kernel if you're in Jupyter Notebook so it's not a good idea. raise command will stop the program.

    0 讨论(0)
  • 2020-12-02 14:45

    If you are working with Spyder, use CTRL + . (DOT) and you will restart the kernel, also you will stop the program.

    0 讨论(0)
  • 2020-12-02 14:48
    • To stop a python script just press Ctrl + C.
    • Inside a script with exit(), you can do it.
    • You can do it in an interactive script with just exit.
    • You can use pkill -f name-of-the-python-script.
    0 讨论(0)
提交回复
热议问题