Definition
The safety protocols built into the pyautogui module to prevent out-of-control scripts from “taking over” the computer and becoming unstoppable.
Why It Matters
An automated script can move faster than a human can react. Without these fail-safes, a buggy script can delete files, send unintended emails, or lock you out of your system in seconds. They are the “emergency brake” that ensures the human operator remains the master of the machine, preventing catastrophic user-interface feedback loops.
Core Concepts
- The Fail-Safe Trigger: Slamming the mouse cursor into any of the four corners of the screen.
- Mechanics: PyAutoGUI checks the mouse position after every function call. If it’s in a corner, it raises
pyautogui.FailSafeException. - The
PAUSEAttribute: Settingpyautogui.PAUSE = 1.0adds a mandatory 1-second delay after every call. This slows down the script to human-manageable speeds and allows the UI to “keep up” with the code. - Global Stop: On most systems,
Ctrl-Alt-Del(Win/Linux) orCmd-Shift-Option-Q(Mac) to log out is the nuclear option for stopping a runaway script.