Python SQLite: database is locked
Solution 1:
I'm presuming you are actually using sqlite3 even though your code says otherwise. Here are some things to check:
- That you don't have a hung process sitting on the file (unix:
$ fuser cache.db
should say nothing) - There isn't a cache.db-journal file in the directory with cache.db; this would indicate a crashed session that hasn't been cleaned up properly.
- Ask the database shell to check itself:
$ sqlite3 cache.db "pragma integrity_check;"
- Backup the database
$ sqlite3 cache.db ".backup cache.db.bak"
- Remove cache.db as you probably have nothing in it (if you are just learning) and try your code again
- See if the backup works
$ sqlite3 cache.db.bak ".schema"
Failing that, read Things That Can Go Wrong and How to Corrupt Your Database Files
Solution 2:
Set the timeout parameter in your connect call, as in:
connection = sqlite.connect('cache.db', timeout=10)