lundi 21 mars 2016

SQLite database gets locked by SELECT clause

I have a python script which creates a database and then enters an infinite loop which runs once per second quering the database with some selects.

At the same time I connect to the database with a sqlite cli and try to make an update but I get a database is locked error.

Here the (anonimized) code of the script:

import sqlite3
import time

con = sqlite3.connect(r'path\to\database.sqlite')

con.execute('DROP TABLE IF EXISTS blah;')
con.execute('CREATE TABLE blah;')
con.execute('INSERT INTO blah;')

con.commit()

while True:
    result = con.execute('SELECT blah')
    print(result.fetchone()[0])
    time.sleep(1)

Aucun commentaire:

Enregistrer un commentaire