Sqlite python sqlite3.OperationalError: database is locked

前端 未结 4 1080
野的像风
野的像风 2020-12-17 17:45

I have written the following code, which is showing the sqlite3.OperationalError: database is locked error. Any help to debug would be much appreciated.

4条回答
  •  死守一世寂寞
    2020-12-17 18:35

    I had the same issue but it was resolved when I used the following to close the concurrent connections.

    conn.close()
    

    So, if your program begins like this:

    import sqlite3
    
    conn = sqlite3.connect('pg_example.db', timeout=10)
    c = conn.cursor()
    

    Make sure that you're including the conn.close() after each SQL statement

    t = ('RHAT',)
    c.execute('SELECT * FROM stocks WHERE symbol=?', t)
    conn.commit()
    conn.close() #This is the one you need
    

提交回复
热议问题