OperationalError:数据库已锁定
我在我的应用程序中做了一些重复的操作(测试它),突然我得到一个奇怪的错误:
I have made some repetitive operations in my application (testing it), and suddenly I’m getting a weird error:
OperationalError: database is locked
我已重新启动服务器,但错误仍然存在.这到底是怎么回事?
I've restarted the server, but the error persists. What can it be all about?
推荐答案
来自 django doc:
From django doc:
SQLite 旨在成为一个轻量级的数据库,因此不能支持高并发.OperationalError:数据库已锁定错误表明您的应用程序正在经历比sqlite 默认可以处理配置.这个错误意味着一个线程或进程具有独占性锁定数据库连接和另一个线程超时等待锁将被释放.
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 的 SQLite 包装器有一个默认值确定多长时间的超时值允许第二个线程等待在超时之前锁上引发 OperationalError: database被锁定错误.
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:
- 切换到另一个数据库后端.在某个时刻,SQLite 对于现实世界的应用程序来说变得过于精简",而这些并发错误表明您已经达到了这一点.
- 重写代码以减少并发并确保数据库事务是短暂的.
- 通过设置超时数据库选项来增加默认超时值
http://docs.djangoproject.com/zh/dev/ref/databases/#database-is-locked-errorsoption
相关文章