Python SQLite: database is locked

后端 未结 20 1165
一生所求
一生所求 2020-12-12 14:24

I\'m trying this code:

import sqlite

connection = sqlite.connect(\'cache.db\')
cur = connection.cursor()
cur.execute(\'\'\'create table item
  (id integer p         


        
20条回答
  •  温柔的废话
    2020-12-12 14:52

    I know this is old, but I'm still getting the problem and this is the first link on Google for it. OP said his issue was that the .db was sitting on a SMB share, which was exactly my situation. My ten minutes' research indicates that this is a known conflict between sqlite3 and smb; I've found bug reports going back to 2007.

    I resolved it by adding the "nobrl" option to my smb mount line in /etc/fstab, so that line now looks like this:

    //SERVER/share /mnt/point cifs credentials=/path/to/.creds,sec=ntlm,nobrl 0 0
    

    This option prevents your SMB client from sending byte range locks to the server. I'm not too up on my SMB protocol details, but I best I can tell this setting would mostly be of concern in a multi-user environment, where somebody else might be trying to write to the same db as you. For a home setup, at least, I think it's safe enough.

    My relevant versions:

    • Mint 17.1 Rebecca
    • SMB v4.1.6-Ubuntu
    • Python v3.4.0
    • SQLite v3.8.2
    • Network share is hosted on a Win12R2 server

提交回复
热议问题