From 7dbefdf1177b0eda02a65f60e8389996b6593718 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 5 Sep 2020 05:54:33 +0530 Subject: [PATCH] Also dont print traceback if db is closed --- src/calibre/db/backend.py | 3 +++ src/calibre/db/backup.py | 2 +- src/calibre/db/cache.py | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/calibre/db/backend.py b/src/calibre/db/backend.py index f01bb104d7..9dac48ecdb 100644 --- a/src/calibre/db/backend.py +++ b/src/calibre/db/backend.py @@ -403,6 +403,7 @@ class DB(object): def __init__(self, library_path, default_prefs=None, read_only=False, restore_all_prefs=False, progress_callback=lambda x, y:True, load_user_formatter_functions=True): + self.is_closed = False try: if isbytestring(library_path): library_path = library_path.decode(filesystem_encoding) @@ -907,6 +908,7 @@ class DB(object): def conn(self): if self._conn is None: self._conn = Connection(self.dbpath) + self.is_closed = False if self._exists and self.user_version == 0: self._conn.close() os.remove(self.dbpath) @@ -1148,6 +1150,7 @@ class DB(object): pass self._conn.close(force) del self._conn + self.is_closed = True def reopen(self, force=False): self.close(force=force, unload_formatter_functions=False) diff --git a/src/calibre/db/backup.py b/src/calibre/db/backup.py index 2218956ba9..911cb5948c 100644 --- a/src/calibre/db/backup.py +++ b/src/calibre/db/backup.py @@ -62,7 +62,7 @@ class MetadataBackup(Thread): try: self.db.check_dirtied_annotations() except Exception: - if self.stop_running.is_set(): + if self.stop_running.is_set() or self.db.is_closed: return traceback.print_exc() try: diff --git a/src/calibre/db/cache.py b/src/calibre/db/cache.py index 3de85edde9..75d1b37b8f 100644 --- a/src/calibre/db/cache.py +++ b/src/calibre/db/cache.py @@ -2127,6 +2127,10 @@ class Cache(object): traceback.print_exc() self.backend.close() + @property + def is_closed(self): + return self.backend.is_closed + @write_api def restore_book(self, book_id, mi, last_modified, path, formats, annotations=()): ''' Restore the book entry in the database for a book that already exists on the filesystem '''