【发布时间】:2010-04-02 21:14:40
【问题描述】:
我有一个 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()
非常感谢。
【问题讨论】: