From e126ddc5180f07fc30e320cdbddc704a99c028d4 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 8 Dec 2010 10:09:52 -0700 Subject: [PATCH] Fix bug in cover cache that could cause it to keep a large number of covers in memory. Showed up when adding large numbers of books to calibre. Fixes #7813 (errors found in terminal after latest stable Calibre closed) --- src/calibre/library/caches.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/calibre/library/caches.py b/src/calibre/library/caches.py index 5b6b79e3df..e19dd8c1ae 100644 --- a/src/calibre/library/caches.py +++ b/src/calibre/library/caches.py @@ -129,6 +129,7 @@ class CoverCache(Thread): # {{{ self.keep_running = True self.cache = {} self.lock = RLock() + self.allowed_ids = frozenset([]) self.null_image = QImage() def stop(self): @@ -175,6 +176,9 @@ class CoverCache(Thread): # {{{ break for id_ in ids: time.sleep(0.050) # Limit 20/second to not overwhelm the GUI + with self.lock: + if id_ not in self.allowed_ids: + continue try: img = self._image_for_id(id_) except: @@ -193,6 +197,7 @@ class CoverCache(Thread): # {{{ def set_cache(self, ids): with self.lock: + self.allowed_ids = frozenset(ids) already_loaded = set([]) for id in self.cache.keys(): if id in ids: