问题描述
我在我的应用程序中做了一些重复的操作(测试它),突然我收到一个奇怪的错误:
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 文档:
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: 数据库被锁定错误.
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/en/dev/ref/databases/#database-is-locked-errorsoption
这篇关于OperationalError: 数据库被锁定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!