gpt4 book ai didi

python - sqlite3.操作错误: database is locked - non-threaded application

转载 作者:太空宇宙 更新时间:2023-11-03 11:11:18 24 4
gpt4 key购买 nike

我有一个 Python 应用程序会抛出标准的 sqlite3.OperationalError: database is locked 错误。我环顾了互联网,找不到任何有效的解决方案(请注意,没有多进程/线程正在进行,正如您所看到的,我已经尝试提高超时参数)。 sqlite文件存储在本地硬盘上。

以下函数是许多访问 sqlite 数据库的函数之一,第一次调用时运行良好,但第二次调用时抛出上述错误(它被称为 for 在另一个函数中循环):

def update_index(filepath):
path = get_setting('Local', 'web')
stat = os.stat(filepath)
modified = stat.st_mtime
index_file = get_setting('Local', 'index')

connection = sqlite3.connect(index_file, 30)
cursor = connection.cursor()
head, tail = os.path.split(filepath)
cursor.execute('UPDATE hwlive SET date=? WHERE path=? AND name=?;', (modified, head, tail))
connection.commit()
connection.close()

非常感谢。

最佳答案

您可能会特别检查保持读锁(未完成游标)的函数。这将阻止更新功能的提交。请注意,有一个专门针对 Python-sqlite 问题的邮件列表:http://groups.google.com/group/python-sqlite

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com