piccolo: sqlite timeout handling
Hi, I often get sqlite3.OperationalError: database is locked, what would be the best way to evade this?
I thought about increasing the lock timeout, but am not sure how to correctly do this when using this library.
Here https://stackoverflow.com/a/39265148 the pragma-statement PRAGMA journal_mode=WAL is recommended. How would I use this with piccolo? I know I can execute raw sql, but doesn’t this need to be re-executed for each connection?
Thank you for your help!
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 24 (15 by maintainers)
@sinisaos OK, cool.
There’s basically two things causing the locks:
timeouthelps with this)BEGINinstead ofBEGIN IMMEDIATE, and the first query in the transaction is aSELECT, then SQLite turns it into areadtransaction. If we then try and do something like anINSERTwithin the transaction, SQLite tries to upgrade it to awritetransaction, but if several connections try doing this, we get the lock error.The problem with
BEGIN IMMEDIATEis it’s less efficient is someone just wants to doSELECTqueries in the transaction. So we will have to allow the user to specify which transaction type they want.@sinisaos Hmm, strange.
What query are you running inside the transaction? Are you also passing
timeouttoSQLiteEngine?