Why doesn't this python keyboard interrupt work? (in pycharm)

前端 未结 7 1252
被撕碎了的回忆
被撕碎了的回忆 2020-12-03 15:28

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:



        
7条回答
  •  臣服心动
    2020-12-03 15:50

    Here is working normally, since i put a variable "x" in your code and i use tabs instead spaces.

    try:
    
        def help():
            print("Help.")
    
        def doStuff():
            print("Doing Stuff")
    
        while True:
            x = int(input())
            if x == 1:
                help()
            elif x == 2:
                doStuff()
            else:
                exit()
    
    except KeyboardInterrupt:
        exit()
    

提交回复
热议问题