From 6a8ea9e65b63999c7200cb0924fbad1b4d1324f8 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 24 Dec 2019 19:12:59 +1000 Subject: [PATCH] if db lock fails, explicitly close database on Windows at least, the database file otherwise remains locked after an exception is raised on a read only file --- anki/storage.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/anki/storage.py b/anki/storage.py index b75a54827..842bb6e2d 100644 --- a/anki/storage.py +++ b/anki/storage.py @@ -63,7 +63,11 @@ def Collection( addBasicModel(col) col.save() if lock: - col.lock() + try: + col.lock() + except: + col.db.close() + raise return col