avoid sqlite deadlock on windows

This commit is contained in:
ed 2022-04-28 22:46:53 +02:00
parent f9c159a051
commit c73ff3ce1b

View file

@ -21,6 +21,12 @@ except:
HAVE_SQLITE3 = False
try:
from pathlib import Path
except:
pass
class U2idx(object):
def __init__(self, conn):
self.log_func = conn.log_func
@ -76,7 +82,22 @@ class U2idx(object):
if not bos.path.exists(db_path):
return None
cur = sqlite3.connect(db_path, 2).cursor()
cur = None
if ANYWIN:
uri = ""
try:
uri = "{}?mode=ro&nolock=1".format(Path(db_path).as_uri())
cur = sqlite3.connect(uri, 2, uri=True).cursor()
self.log("ro: {}".format(db_path))
except:
self.log("could not open read-only: {}\n{}".format(uri, min_ex()))
if not cur:
# on windows, this steals the write-lock from up2k.deferred_init --
# seen on win 10.0.17763.2686, py 3.10.4, sqlite 3.37.2
cur = sqlite3.connect(db_path, 2).cursor()
self.log("opened {}".format(db_path))
self.cur[ptop] = cur
return cur