KeyboardInterrupt Python Origin: Application & API Last updated 13 Oct 2026

KeyboardInterrupt (script stopped with Ctrl+C) / ^C traceback

The script was interrupted (Ctrl+C, SIGINT, or a container stop), producing a KeyboardInterrupt traceback.

Seen on: Python

Meaning

Not a bug in itself — but long-running scripts should catch it to clean up (close files, flush data) and exit gracefully. Docker sends SIGTERM first, which Python doesn’t handle by default.

Common causes

  • Manual Ctrl+C
  • Process manager or container stop
  • Infinite loop that had to be interrupted

⚡ Quick fix

  1. Wrap the main loop in try/except KeyboardInterrupt to clean up
  2. Handle SIGTERM with the signal module in containers
  3. Fix infinite loops if the interrupt was needed

Detailed fix by platform

Python

  1. python
    import signal, sys
    signal.signal(signal.SIGTERM, lambda *_: sys.exit(0))

How to diagnose

  1. Trigger — Who interrupted it?
  2. Cleanup — Was data left half-written?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

AttributeError — AttributeError: 'X' object has no attribute 'y' (Python)AttributeErrorCannot allocate memory — fork: Cannot allocate memory / ENOMEM (Linux)Cannot allocate memoryEADDRINUSE — Error: listen EADDRINUSE: address already in use :::3000 (Node.js)EADDRINUSEEPIPE — Error: write EPIPE (Node.js)EPIPEEvent loop is closed — RuntimeError: Event loop is closed (Python)Event loop is closedfork: retry: Resource temporarily unavailable — fork: retry: Resource temporarily unavailable (process/thread limit) (Linux)fork: retry: Resource…maxBuffer exceeded — RangeError [ERR_CHILD_PROCESS_STDIO_MAXBUFFER]: stdout maxBuffer length exceeded (Node.js)maxBuffer exceededOSError Errno 98 — OSError: [Errno 98] Address already in use (Python)OSError Errno 98KeyboardI…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.