Skip to content
Advertisement

What is the purpose of the pyautogui failsafe?

So, I was just messing around with pyautogui moving the mouse to random positions on the screen, when I manually moved the mouse to the top left corner of the screen and ran the program, it raised a pyautogui failsafe.

I do know how to disable it and all that, but I want to know why is is there in the first place and possible use cases

Code:

import pyautogui
pyautogui.click(x=25, y=1048)
time.sleep(2) # I moved the move to the corner of the screen during this time delay
pyautogui.click(x=701, y=430)

Error:

Traceback (most recent call last):
  File "C:1 Files and FoldersfolderPython ProjectPythonCODEMy ProjectsAutomation.py", line 23, in <module>
    job()
  File "C:1 Files and FoldersfolderPython ProjectPythonCODEMy ProjectsAutomation.py", line 18, in job
    pyautogui.click(x=1475, y=141)
  File "C:UsersMy_userAppDataLocalProgramsPythonPython39-32libsite-packagespyautogui__init__.py", line 585, in wrapper
    failSafeCheck()
  File "C:UsersMy_userAppDataLocalProgramsPythonPython39-32libsite-packagespyautogui__init__.py", line 1710, in failSafeCheck
    raise FailSafeException(
pyautogui.FailSafeException: PyAutoGUI fail-safe triggered from mouse moving to a corner of the screen. To disable this fail-safe, set pyautogui.FAILSAFE to False. DISABLING FAIL-SAFE IS NOT RECOMMENDED.

Advertisement

Answer

According to pyautogui docs

It’s hard to use the mouse to close a program if the mouse cursor is moving around on its own.

As a safety feature, a fail-safe feature is enabled by default. When a PyAutoGUI function is called, if the mouse is in any of the four corners of the primary monitor, they will raise a pyautogui.FailSafeException.

So simply FailSafe is just thing that if your program just spams the mouse or doing something that you cannot stop it, You can close that in this way, For more information read it docs pyautogui docs

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement