Search code examples
pythonexitpython-idle

Python: Quit IDLE after Script running


Is it possible to somehow quit Python IDLE under Windows from within my python code/script at the end after running?

I tried something like:

import sys
sys.exit(0) # or exit(1)

didn't work. Probably only quits the current "process" of the running python script. Thanks a lot


Solution

  • If you can run IDLE from the command line (or edit your shortcut), I found this in the IDLE help.

    If IDLE is started with the -n command line switch it will run in a
    single process and will not create the subprocess which runs the RPC
    Python execution server.
    

    Which seems to imply that the script is running inside IDLE. I did a quick test script, and calling exit() brought up a box asking to kill the program. Clicked yes, and the script and IDLE both quit. Hope that can help.