How to stop/terminate a python script from running?

后端 未结 16 1751
-上瘾入骨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
    

提交回复
热议问题