簡體   English   中英

sqlite3.OperationalError:數據庫被鎖定 - 非線程應用程序

[英]sqlite3.OperationalError: database is locked - non-threaded application

我有一個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

您是否真的需要為每個UPDATE連續打開和關閉數據庫文件? 如果在訪問數據庫的每個函數中執行相同的操作,是否可能已從另一個已使用不同連接打開數據庫並且正在修改數據庫的函數中調用update_index函數?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM