KeyboardInterrupt 未捕获异常

KeyboardInterrupt not catching exception

我已经通读了各种主题和官方文档,但我似乎无法通过热键停止该主题。我需要右击vscodes输出中的运行ning代码window和select停止代码运行.

Ctrl+C 和 Delete 不会停止来自 运行ning 的代码。理想情况下,我想知道如何更改按键以停止来自 运行ning 的代码。

我在 open CV 中使用它,我希望与 pyautogui 类似。

if cv.waitKey(1) == ord('q'):
    cv.destroyAllWindows()
    break` 

我遇到的循环:

try:
    while True:   
        for image in image_list:
            name = image
            location = py.locateCenterOnScreen(image, confidence=0.9)
            print(name + " Found at: " + str(location))

except KeyboardInterrupt:
    pass
    print("Interrupted")

我认为异常在循环“内部”,所以它应该被捕获但是当我尝试 exit/break.

时什么也没有发生

我使用的是运行代码而不是运行Python终端中的文件

运行代码由扩展代码运行ner提供,只会显示结果OUTPUT 并且不接受输入.