2

When I was trying python on cmd prompt and I was trying to exit to install a package, the sentence "keyboard interrupt" was displayed instead of actually exiting. I couldn't find a "break" key to try ctrl + break, so I kept trying with ctrl + c. I tried the default settings, removing the quick edit mode, and run as administrator, I just can't seem to exit out of python.

Any help with this problem would be much appreciated.

4
  • This? Feb 8, 2020 at 23:35
  • Thank you so much, @KamilMaciorowski ! It worked. But I am just annoyed that ctrl + c didn't work.
    – S.R.
    Feb 8, 2020 at 23:37
  • I would expect Ctrl+d but I know neither Python nor cmd.exe. Feb 8, 2020 at 23:41
  • Ctrl-C does not break out of simple Terminal in Kali, so I expect it is just the way Linux is
    – John
    Feb 9, 2020 at 0:28

2 Answers 2

3

On Windows, in the interactive Python interpreter, the options to exit are:

  • quit()

  • exit()

  • Ctrl + Z then Enter

  • Ctrl + Break

When running scripts, Ctrl + C can generally be used to send a KeyboardInterrupt that halts script execution (note that a Traceback will be generated).


The Ctrl + Break option assumes your keyboard has a Break or Pause/Break key.

1

Due to a design decision, the Python interpeter does not exit on Ctrl+C,
but rather on Ctrl+D or the command exit().

3
  • 1
    I'm a Linux guy and I find normal that interactive interpreters (e.g. shells) use Ctrl+D for this, not Ctrl+C. I think even cmd.exe in Windows doesn't exit on Ctrl+C. Why should Python differ? In this context "unknown reason" seems unjustified. Feb 9, 2020 at 0:34
  • @KamilMaciorowski: I rephrased the introductory sentence. However, CTRL-C (C for Cancel) seems to be the most widespread key combination for exiting some sub-space. Unless you argue for CTRL-D (D for delete)...
    – zx485
    Feb 9, 2020 at 0:38
  • It could be that the process running the python interpreter at least originally needed a quit option as well, thus CTRL-C would be ambiguous if used for both the interpreter and the host program? Feb 9, 2020 at 2:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.