-1

I want to interrupt my while True loop in below code but it does not work:

try:  
    while True:  
        print(1)    
except KeyboardInterrupt:  
    print('interrupted!')  
    exit()

I am running this code in PyCharm. Why isn't Ctrl+C triggering KeyboardInterrupt?

2 Answers2

2

Have you tried pressing Ctrl+C, because that's the correct way of causing KeyboardInterrupt

As @Chris mentioned it won't work for pycharm. Try using Ctrl+F2 for that

ReKx
  • 996
  • 2
  • 10
  • 23
2

In PyCharm Ctrl+C is bound to "copy". Try Ctrl+F2 instead.

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257