pgref.dev/sqlite/errors/SQLITE_INTERRUPT
SQLITE_INTERRUPTWARNINGTier 2 — Caution⚠️ MEDIUM confidence

Operation terminated by sqlite3_interrupt()

Category: Control FlowVersions: 3.0+

🔴 Production Risk Error

Low — the interrupt is intentional; handle the error and retry or report to user.

What this means

SQLITE_INTERRUPT (9) is returned when sqlite3_interrupt() is called from another thread while an SQL operation is in progress, causing it to terminate early.

Why it happens

  1. 1sqlite3_interrupt() called from a signal handler or timeout thread.
  2. 2Application-level query timeout mechanism fired.

How to reproduce

Long-running queries interrupted by a watchdog thread.

trigger — this will ERROR
import sqlite3, threading, time
conn = sqlite3.connect(':memory:')
conn.execute('CREATE TABLE t(x)')
conn.executemany('INSERT INTO t VALUES(?)', [(i,) for i in range(100000)])

def interrupt():
    time.sleep(0.01)
    conn.interrupt()

threading.Thread(target=interrupt, daemon=True).start()
try:
    conn.execute('SELECT sum(x*x) FROM t, t, t').fetchall()
except sqlite3.OperationalError as e:
    print(e)  # interrupted
sqlite3.OperationalError: interrupted

Fix 1

Why this works

Retry the query if the interrupt was from a soft timeout and the operation should succeed.

Fix 2

Why this works

Increase the timeout threshold before calling interrupt().

Fix 3

Why this works

Break large queries into smaller chunks to avoid needing interrupts.

Sources

📚 Official docs: https://www.sqlite.org/rescode.html#interrupt

🔧 Source ref: sqlite3.h — SQLITE_INTERRUPT = 9

📖 Further reading: sqlite3_interrupt()

Confidence assessment

⚠️ MEDIUM confidence

Stable.

See also

📄 Reference pages

sqlite3_interrupt
⚙️ This error reference was generated with AI assistance and reviewed for accuracy. Examples are provided to illustrate common scenarios and may not cover every case. Always test fixes in a development environment before applying to production. Spotted an error? Suggest a correction →