I am trying write two processes using python that require access to same sqlite database table. One of the process updates the table by inserting new data and the other process retrieves information from the same table. However when the other second process runs select query the data base is already locked and I get the "OperationalError: database is locked". Following are the code for both processes. Appreciate any help
process : 1
------------
while True:
print "Updating"
try:
conn = sqlite3.connect('test.db')
c = conn.cursor()
c.execute('PRAGMA journal_mode = WAL')
c.executemany('INSERT INTO test_table VALUES (?,?,?,?,?)', insertdata)
conn.commit()
conn.close()
except:
pass
time.sleep(60)
process : 2
------------
conn = sqlite3.connect('test.db')
c = conn.cursor()
c.execute("select * from test_table where id='{}' and date = '{}' order by time desc".format(recv_data,datetime.datetime.now().date().isoformat()))
data= c.fetchall()
conn.close()
Aucun commentaire:
Enregistrer un commentaire