码迷,mamicode.com
首页 > 数据库 > 详细

SQLite数据库“Database is locked”解决办法

时间:2020-06-26 18:20:12      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:red   The   get   ror   real   error   nal   efault   tab   

“Database is locked” errors

SQLite is meant to be a lightweight database, and thus can’t support a high level of concurrency. OperationalError: database is locked errors indicate that your application is experiencing more concurrency than sqlite can handle in default configuration. This error means that one thread or process has an exclusive lock on the database connection and another thread timed out waiting for the lock the be released.

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:

‘OPTIONS‘: {
# ...
‘timeout‘: 20,
# ...
}
This will make SQLite wait a bit longer before throwing “database is locked” errors; it won’t really do anything to solve them.

SQLite数据库“Database is locked”解决办法

标签:red   The   get   ror   real   error   nal   efault   tab   

原文地址:https://www.cnblogs.com/JeromeLong/p/13195521.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!