Use recursive locks for the cover caches

Performance hit of a few nanoseconds per lock operation, however
eliminates one source of deadlocks.
This commit is contained in:
Kovid Goyal 2026-01-16 20:07:07 +05:30
parent 65823b271f
commit 9384b8d75c
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 4 additions and 4 deletions

View File

@ -13,7 +13,7 @@ import tempfile
from collections import OrderedDict, namedtuple
from contextlib import suppress
from locale import localeconv
from threading import Lock
from threading import RLock
from calibre import as_unicode, prints
from calibre.constants import cache_dir, get_windows_number_formats, iswindows, preferred_encoding
@ -136,7 +136,7 @@ class ThumbnailCache:
self.group_id = 'group'
self.thumbnail_size = thumbnail_size
self.size_changed = False
self.lock = Lock()
self.lock = RLock()
self.min_disk_cache = min_disk_cache
if test_mode:
self.log = self.fail_on_error

View File

@ -12,7 +12,7 @@ from collections import OrderedDict
from collections.abc import Iterable, Iterator, MutableMapping
from functools import partial
from queue import Empty, LifoQueue, Queue, ShutDown
from threading import Event, Lock, Thread, current_thread
from threading import Event, RLock, Thread, current_thread
from time import monotonic
from typing import TypeVar
@ -46,7 +46,7 @@ class RAMCache(MutableMapping[int, T]):
def __init__(self, limit=100):
self.items = OrderedDict[int, T]()
self.lock = Lock()
self.lock = RLock()
self.limit = limit
self.pixmap_staging: list[T] = []
self.gui_thread = current_thread()