KeyboardInterrupt in Python — What It Means and How to Fix It
What Python's KeyboardInterrupt exception means and how to resolve it.
Published October 28, 2026
KeyboardInterrupt is raised when the user interrupts program execution, typically by pressing Ctrl+C.
Key points
- Catch it specifically with "except KeyboardInterrupt:" when you want to handle this exact case rather than a bare except
Example
Often caught deliberately to allow a program to shut down cleanly