spyder: Ctrl+C not working when using input on Windows

Description

Keyboard interrupt freezes but doesn’t exit script.

What steps will reproduce the problem?

  1. Use python code:
while True:
    input()
  1. Type, and press return once or a few times.
  2. Press Ctrl-C or Crtl-Shift-C
  3. Console lets you continue typing, but doesn’t respond to an enter/return. Pressing stop doesn’t work as expected, only escape seems to be restarting kernel.
  4. Also try:
try:
    while True:
        print(input())
except KeyboardInterrupt:
    print('Done.')

With similar results. What is the expected output? What do you see instead? Expect to see some sort of error message, or ‘Done.’ printed to the console if the error is handled with try/except. Instead I see no visible change. Can keep inputting text, on last line, but enter/return fails to work after attempting keyboard interrupt.

Please provide any additional information below

Version and main components

  • Spyder Version: 3.2.1
  • Python Version: 3.6.1
  • Qt Versions: 5.6.2, PyQt5 5.6 on Windows

Dependencies

pyflakes >=0.6.0 :  1.5.0 (OK)
pycodestyle >=2.3:  2.3.1 (OK)
pygments >=2.0   :  2.2.0 (OK)
pandas >=0.13.1  :  0.20.1 (OK)
numpy >=1.7      :  1.12.1 (OK)
sphinx >=0.6.6   :  1.5.6 (OK)
rope >=0.9.4     :  0.9.4-1 (OK)
jedi >=0.9.0     :  0.10.2 (OK)
nbconvert >=4.0  :  5.1.1 (OK)
sympy >=0.7.3    :  1.0 (OK)
cython >=0.21    :  0.25.2 (OK)
qtconsole >=4.2.0:  4.3.0 (OK)
IPython >=4.0    :  5.3.0 (OK)
pylint >=0.25    :  1.6.4 (OK)

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 1
  • Comments: 18 (5 by maintainers)

Most upvoted comments

Sorry but we don’t have plans to solve this problem because it’s a very minor issue.

You’re welcome to send us a pull request if you find the solution for it. Thanks!

It would be so nice if ctrl-c acted like it does in every OS terminal. E.g., when I have a long command half-written, I want to be able to hit ctrl-c to just cancel it and return a fresh new line for me to work on. Instead I end up fumbling around trying to figure out what is going on, or just delete each character manually, or just press enter and take the exception.

Would be a huge bonus to make ctrl-c act like the naive user expects it to act in Spyder. This has been bugging me for years.

Just make it act like it does in Matlab, that would be so beautiful.

Sorry but we don’t have plans to solve this problem because it’s a very minor issue.

You’re welcome to send us a pull request if you find the solution for it. Thanks!

Seems developer attitude is bad. Bye bye spyder. hello pycharm…

Actually, this issue is worse than reported previously because the same problems exist with just a regular input (no while loop reqquired). Just try this:

print('You said: ', input('Say something: '))

When you click on the “Stop the current command” button, this is what you get as output:

You said:  exit

Say something:

So apart from the printed message ending up above the prompt from input(), it seems that clicking the button never stopped the command execution, but instead only passed “exit” to input().

In addition, and in line with the original report, pressing Ctrl+c instead of clicking the button, kills all further responses from the console and you can only restart the kernel.

I really don’t think this is a minor issue, but one that clearly affects usability.

This is a very special case because you put an input inside an infinite loop. To exit the loop, you can press the square red button present in all consoles.

I have the same problem - also in finite loops - I can’t find any way to stop execution in Spyder - Control+C, red button, blue stop button - nothing works…

This was (finally) fixed by the Jupyter team in https://github.com/ipython/ipykernel/pull/498. So, until we release a new version of spyder-kernels that requires a version of ipykernel with that fix, you can simply run

conda install ipykernel=5.3.4

to get it.

I have the same problem - also in finite loops - I can’t find any way to stop execution in Spyder - Control+C, red button, blue stop button - nothing works…

For now, the only solution is to restart the kernel