Why doesn't this python keyboard interrupt work? (in pycharm)
<p>My python try/except loop does not seem to trigger a keyboard interrupt when Ctrl + C is pressed while debugging my code in pycharm. My code look like this:</p>

<pre><code>numbers = []
loop = True

try: 
    # ===========SUBROUTINES==================

    def help():
        print("To view the list type 'view'"
              "\n To add an item type 'add'"
              "\n To remove an item type 'remove'"
              "\n To exit type exit or Ctrl + c can be used at any time")

    # =========SUBROUTENES END===============


    while loop:
        task = input("What do you want to do? Type \"help\" for help:- ")
        if task == 'help':
            help()
        else:
            print("Invalid return please try again.")

    except KeyboardInterrupt:
        exit()
</code></pre>

<p><strong>EDIT:</strong> There seems to be some problems with my slimmed down code working and not producing the same error. The full code can be viewed <a href="https://gist.github.com/shardros/61901ba8a70caf0a12b00b3a61b2a88e" rel="nofollow">here</a>. I have also re-slimed down the code (The code above) and it has produced the same error.</p>

<p>From your screen shot it appears that you are running this code in an IDE. The thing about IDEs is that they are not quite the same as running normally, especially when it comes to handling of keyboard characters. The way you press ctrl-c, your IDE thinks you want to copy text. The python program never sees the character. Pehaps it brings up a separate window when running? Then you would select that window before ctrl-c.</p>

python pycharm try-except keyboardinterrupt