python - 操作错误 : database is locked

标签 python django database sqlite locked

我在我的应用程序中做了一些重复的操作(测试它),突然我得到一个奇怪的错误:

OperationalError: database is locked

我已重新启动服务器,但错误仍然存​​在。这到底是怎么回事?

最佳答案

来自 django 文档:

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

http://docs.djangoproject.com/en/dev/ref/databases/#database-is-locked-errorsoption

关于python - 操作错误 : database is locked,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3172929/

相关文章:

python - IRC 机器人使循环休眠而不中断主循环

python mysql.connector fetchall() 运行速度极慢

django - 在 Amazon Elastic Beanstalk 上使用 Docker 部署 Django

mysql - 有什么办法可以加快这个查询吗?

php - Eloquent ORM Active Record - 这是正确的方法吗?

python - 将具有日期时间值的列转换为每周的列

mysql - Django 查询与同一个表上的另一个查询连接

Django - 如何在生产服务器上运行它?

database - 用 Spark Dataframe 中另一个分类列的平均值替换列的空值

python将记录一一显示为问题