Katkoota
Katkoota

Reputation: 23

How to catch "Python Not Responding" exception?

I used this function below to keep the Python program pressing 'enter" over and over again, but when I click with the mouse, a window appears with "Python Not Responding" and then I have to close the program, so my question is; is there any way for me to catch that with Python?

Code:

def stop():
    pyautogui.FAILSAFE = False
    while True:
        pyautogui.press('enter')

Thanks in advance!

Upvotes: 0

Views: 106

Answers (1)

Erik McKelvey
Erik McKelvey

Reputation: 1627

You cannot catch your program crashing as if it were an exception. What you can do in add a delay between sending each key press:

import time
def stop():
    pyautogui.FAILSAFE = False
    while True:
        pyautogui.press('enter')
        time.sleep(0.1)

Upvotes: 1

Related Questions