conn = sqlite3.connect('mydb')
conn.close()
try:
    resultset = conn.execute('SELECT 1 FROM my_table LIMIT 1;')
except sqlite3.ProgrammingError as e:
    pass
How to tell if Python SQLite database connection or cursor is closed?