Python’s SQLite wrapper has a default timeout value that determines how long the second thread is allowed to wait on the lock before it times out and raises the OperationalError: database is locked error.
If you’re getting this error, you can solve it by:
- Switching to another database backend. At a certain point SQLite becomes too “lite” for real-world applications, and these sorts of concurrency errors indicate you’ve reached that point.
- Rewriting your code to reduce concurrency and ensure that database transactions are short-lived.
- Increase the default timeout value by setting the timeout database option option:
'OPTIONS': {This will simply make SQLite wait a bit longer before throwing “database is locked” errors; it won’t really do anything to solve them.
# ...
'timeout': 20,
# ...
}
Please refer to https://docs.djangoproject.com/en/dev/ref/databases/#database-is-locked-errors
In my case, I took solution 3 add timeout option to solve this problem.
No comments:
Post a Comment