From 0c8b6a80a0c484c87e6f17fce36d1629b0889221 Mon Sep 17 00:00:00 2001 From: David Manthey Date: Thu, 2 Feb 2023 08:50:48 -0500 Subject: [PATCH] Fix an issue with the multi source last open cache. --- CHANGELOG.md | 2 +- .../large_image_source_multi/__init__.py | 23 +++++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 472b9d68f..536854944 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ - ICC color profile support ([#1037](../../pull/1037), [#1043](../../pull/1043)) ### Improvements -- Speed up generating tiles for some multi source files ([#1035](../../pull/1035)) +- Speed up generating tiles for some multi source files ([#1035](../../pull/1035), [#1047](../../pull/1047)) - Render item lists faster ([#1036](../../pull/1036)) - Reduce bioformats source memory usage ([#1038](../../pull/1038)) - Better pick the largest image from bioformats ([#1039](../../pull/1039), [#1040](../../pull/1040)) diff --git a/sources/multi/large_image_source_multi/__init__.py b/sources/multi/large_image_source_multi/__init__.py index 1c9eef3a2..7e385faa3 100644 --- a/sources/multi/large_image_source_multi/__init__.py +++ b/sources/multi/large_image_source_multi/__init__.py @@ -5,6 +5,7 @@ import math import os import re +import threading import warnings from pathlib import Path @@ -388,6 +389,7 @@ def __init__(self, path, **kwargs): super().__init__(path, **kwargs) self._largeImagePath = self._getLargeImagePath() + self._lastOpenSourceLock = threading.RLock() if not os.path.isfile(self._largeImagePath): try: possibleYaml = self._largeImagePath.split('multi://', 1)[-1] @@ -804,10 +806,11 @@ def _openSource(self, source, params=None): :param params: a dictionary of parameters to pass to the open call. :returns: a tile source. """ - if (hasattr(self, '_lastOpenSource') and - self._lastOpenSource['source'] == source and - self._lastOpenSource['params'] == params): - return self._lastOpenSource['ts'] + with self._lastOpenSourceLock: + if (hasattr(self, '_lastOpenSource') and + self._lastOpenSource['source'] == source and + self._lastOpenSource['params'] == params): + return self._lastOpenSource['ts'] if not len(large_image.tilesource.AvailableTileSources): large_image.tilesource.loadTileSources() if ('sourceName' not in source or @@ -815,14 +818,16 @@ def _openSource(self, source, params=None): openFunc = large_image.open else: openFunc = large_image.tilesource.AvailableTileSources[source['sourceName']] - self._lastOpenSource = { - 'source': source, - 'params': params, - } + origParams = params if params is None: params = source.get('params', {}) ts = openFunc(source['path'], **params) - self._lastOpenSource['ts'] = ts + with self._lastOpenSourceLock: + self._lastOpenSource = { + 'source': source, + 'params': origParams, + 'ts': ts + } return ts def getAssociatedImage(self, imageKey, *args, **kwargs):