Forums

Exiting from Python Console

I want to exit from the python console from the program itself. The following link starts the console https://www.pythonanywhere.com/user/hemantjha/files/home/hemantjha/hello.py?run

In the hello.py I have sys.exit() in the end. I am expecting it to exit the python console when the program execution ends. Currently it doesn't do that. The python console remains active and I have to kill it from the console tab. How can I exit from the python console once I start it up.

Hmm, that's interesting. The ?run URLs are really designed for debugging your code, so we make them remain in Python once your code has executed so that you can look at variables' values and that kind of thing.

What are you trying to do with your Python script that makes it need to exit at the end? Perhaps there's another way of achieving the same end. One possibility: you could create a custom console type on the "Consoles" tab, and set the command to run to python3.4 /home/hemantjha/hello.py -- that would kill the console when it had finished running.