From c73ff3ce1bca44cfe6e57ca99c3b4a644bed9151 Mon Sep 17 00:00:00 2001 From: ed Date: Thu, 28 Apr 2022 22:46:53 +0200 Subject: [PATCH] avoid sqlite deadlock on windows --- copyparty/u2idx.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/copyparty/u2idx.py b/copyparty/u2idx.py index 566bb146..fbc784ea 100644 --- a/copyparty/u2idx.py +++ b/copyparty/u2idx.py @@ -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