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

    Sep 16, 2008 · quit() exit(0) os._exit(0) sys.exit(0) os.kill(os.getppid(), 9) - where os.getppid() is the pid of parent process; The last one killed the main process and itself but the rest processes were still alive. Solution. I had to kill it by external command and finally found the …

  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. How to exit Python script in Command Prompt? - Stack Overflow

    Jan 8, 2017 · For an embedded python (e.g. python-3.6.8-embed-win32) quit() command does not work. Python 3.6.8 (tags/v3.6.8:3c6b436a57, Dec 23 2018, 23:31:17) [MSC v.1916 32 bit (Intel)] on win32 >>> quit() Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'quit' is not defined The only way that works is: CTRL + Z then ...

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

    Nov 3, 2013 · After all, one of the most likely things a newbie will try to exit Python is typing in quit. Nevertheless, quit should not be used in production code. This is because it only works if the site module is loaded. Instead, this function should only be used in the interpreter. exit() is an alias for quit (or vice-versa). They exist together simply ...

  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. 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 …

  7. 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 …

  8. 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.

  9. Exiting from python Command Line - Stack Overflow

    Mar 16, 2021 · The python command line is a read-evaluate-print-loop, that is when you type text it will read that text, evaluate it, and eventually print the result. When you type exit() it evaluates to a callable object of type site.Quitter and calls its __call__ function which exits the system.

  10. python - Proper way to quit/exit a PyQt program - Stack Overflow

    So quit() or exit() are nothing like sys.exit(). The latter will terminate the program, but the former will merely terminate the event-loop (if it's running). When the user cancels the login dialog, your example should just call sys.exit() to terminate the program. Otherwise, your program will just get stuck in the blocking while-loop.