操作错误:数据库被锁定 [英] operational error: database is locked
问题描述
这就是我所做的
import sqlite3
conn = sqlite.connect('/ home / pjbardolia /mysite/tweet_count.db')
c = conn.cursor()
c.execute(create table count_twitter(count_id integer primary key autoincrement,count_present integer not null,last_tweet not null) )
c.execute(insert into count_twitter values('',10,10))
然而,在执行插入语句后,我得到操作错误:数据库被锁定。
有人可以简单地告诉我这个错误是什么意思?以及如何解决它。
在此先感谢
这是这个错误的意思:
SQLite应该是一个轻量级的数据库,因此不能支持
的高级并发性。 OperationalError:数据库被锁定错误
表明你的应用程序正在经历比
更多的并发性sqlite可以在默认配置下处理。这个错误意味着一个
线程或进程对数据库连接有一个独占锁,而
另一个线程超时等待锁被释放。
< Python的SQLite包装有一个默认的超时值,它决定了
第二个线程在
超时之前允许等待的时间,并引发OperationalError:数据库被锁定的错误。
如果遇到这个错误,可以通过以下方法解决:
切换到另一个数据库后端。在某个时刻,SQLite
对于真实世界的应用程序来说太精简了,这些
并发性错误表明你已经达到了这一点。
重写您的代码以降低并发性,并确保数据库
事务是短暂的。
通过设置超时数据库$ b来增加默认的超时值$ b选项选项选项
可能在代码中有另一个连接没有关闭或未提交,这会导致此错误。基本上试图做第二个执行
当它已经被另一个锁定。如果你真的想要并发交易,你需要有一个 RDBMS 。
So I know this problem is not new in flask, and people have already asked it before. However I am still facing a problem while executing my database commands in bash as I am new to python. This is what i did
import sqlite3
conn = sqlite.connect('/home/pjbardolia/mysite/tweet_count.db')
c = conn.cursor()
c.execute("create table count_twitter (count_id integer primary key autoincrement ,count_present integer not null,last_tweet not null)")
c.execute(insert into count_twitter values('',10,10))
however after executing insert statement I am getting operational error: database is locked. Can someone tellme in simple terms what does this error means? and how to solve it. Thanks in advance
This is what this error means:
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
Probably you have another connection in your code that is not closed or not committed and this cause this error. Basically trying to do second execute
when it is already locked by the another one. If you really want to have your concurrent transactions you need to have a RDBMS.
这篇关于操作错误:数据库被锁定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!