我在我的应用程序中做了一些重复的操作(测试),突然,我得到一个奇怪的错误:
OperationalError:数据库已锁定我已重新启动服务器,但错误仍然存在。
来自django doc:>SQLite是一个轻量级的数据库,因此不能支持的高水平并发性。 OperationalError:数据库被锁定错误指示您的应用程序遇到比更多的并发性sqlite可以在默认配置中处理。这个错误意味着一个线程或进程在数据库连接上有一个独占的锁,而另一个线程超时等待锁释放。
Python的SQLite包装器有一个默认的超时值,它决定了第二个线程允许等待在锁定超时之前的时间,引发OperationalError:database 是被锁定的错误。
如果你得到这个错误,你可以解决它: / p>
切换到另一个数据库后端。 在某一点上,SQLite对于现实世界的应用程序变得过于lite,和这些类型的并发错误表明你已经达到了这一点。
重写代码以减少并发,并确保数据库的交易是短期的。
将默认超时值增加设置超时数据库选项 optionoption
docs.djangoproject/en/dev/ref/databases/#数据库锁定错误选择
I have made some repetitive operations in my application (testing it), and suddenly I’m getting a weird error:
OperationalError: database is lockedI've restarted the server, but the error persists. What can it be all about?
解决方案From django doc:
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 optionoption
docs.djangoproject/en/dev/ref/databases/#database-is-locked-errorsoption
更多推荐
OperationalError:数据库被锁定
发布评论