About 32,300 results
Open links in new tab
  1. python - How do I terminate a script? - Stack Overflow

    Sep 16, 2008 · Keep in mind that sys.exit(), exit(), quit(), and os._exit(0) kill the Python interpreter. Therefore, if it appears in a script called from another script by execfile() , it stops execution of both scripts.

  2. How to properly quit a program in python - Stack Overflow

    Oct 23, 2012 · There is sys.exit() which is part of the sys module, and there is exit() and quit() which is a built-in. However, sys.exit() is intended for programs not in IDLE (python interactive), while the built-in exit() and quit() functions are intended for use in IDLE.

  3. Python exit commands - why so many and when should each be …

    Nov 3, 2013 · quit() simply raises the SystemExit exception. Furthermore, if you print it, it will give a message: >>> print (quit) Use quit() or Ctrl-Z plus Return to exit >>> This functionality was included to help people who do not know Python. After all, one of the most likely things a newbie will try to exit Python is typing in quit.

  4. python - Is there a method that tells my program to quit ... - Stack ...

    Jun 10, 2010 · For the "q" (quit) option in my program menu, I have the following code: elif choice == "q": print() That worked all right until I put it in an infinite loop, which kept printing blank lines. Is

  5. How to stop/terminate a python script from running?

    While the previous answers are helpful, they don't always work in all situations. If you have a Python-CV window open, which is waiting for a key press to quit, while running from inside vim, as a (weirdly specific) example, and you accidentally close the window normally, it will continue to run and Ctrl+C and Ctrl+Z might simply print to the terminal and get ignored.

  6. Programmatically stop execution of python script? [duplicate]

    The exit() and quit() built in functions do just what you want. No import of sys needed. No import of sys needed. Alternatively, you can raise SystemExit , but you need to be careful not to catch it anywhere (which shouldn't happen as long as you specify the type of …

  7. How do I abort the execution of a Python script? [duplicate]

    Jan 26, 2010 · There is also an _exit() function in the os module. The sys.exit() function raises a SystemExit exception to exit the program, so try statements and cleanup code can execute. The os._exit() version doesn't do this. It just ends the program without doing any cleanup or flushing output buffers, so it shouldn't normally be used.

  8. How do I stop a program when an exception is raised in Python?

    Jan 13, 2009 · @kramer65: A program exit code of 0 means "finished without errors". Since the sys.exit call appears to be caused by an error, it should yield a program exit code that is not 0. 1 is just a suggestion. –

  9. exit - Best way to quit a python programme? - Stack Overflow

    Apr 21, 2018 · Generally, the best way to end a Python program is just to let the code run to completion. For example, a script that looks for "hello" in a file could look like this:

  10. Terminating a Python Program - Stack Overflow

    +1 on using a return statement instead. Using a return statement (with or without a return value) means that your python program can be used from within an interactive session, or as part of some other script. I get very irritated at scripts that call sys.exit and dump me out of …

Refresh