Skip to content

Commit

Permalink
Merge pull request #1047 from girder/multi-source-lock
Browse files Browse the repository at this point in the history
Fix an issue with the multi source last open cache.
  • Loading branch information
manthey authored Feb 2, 2023
2 parents 42eefe7 + 0c8b6a8 commit a4fdbcf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
23 changes: 14 additions & 9 deletions sources/multi/large_image_source_multi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import math
import os
import re
import threading
import warnings
from pathlib import Path

Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -804,25 +806,28 @@ 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
source['sourceName'] not in large_image.tilesource.AvailableTileSources):
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):
Expand Down

0 comments on commit a4fdbcf

Please sign in to comment.