Skip to content

Commit

Permalink
Merge pull request #1457 from girder/openslide-retry
Browse files Browse the repository at this point in the history
Retry read_region if openslide reports an error
  • Loading branch information
manthey authored Feb 1, 2024
2 parents 6e5394b + 0eb98cb commit 686025e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Infer DICOM file size, when possible ([#1448](../../pull/1448))
- Swap styles faster in the frame viewer ([#1452](../../pull/1452))
- Reduce color fringing in multi source compositing ([#1456](../../pull/1456))
- Retry read_region if openslide reports an error ([#1457](../../pull/1457))

### Bug Fixes
- Fix an issue with compositing sources in the multi source caused by alpha range ([#1453](../../pull/1453))
Expand Down
23 changes: 15 additions & 8 deletions sources/openslide/large_image_source_openslide/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,14 +297,21 @@ def getTile(self, x, y, z, pilImageAllowed=False, numpyAllowed=False, **kwargs):
if svslevel['scale'] > 2 ** self._maxSkippedLevels:
tile = self._getTileFromEmptyLevel(x, y, z, **kwargs)
else:
try:
tile = self._openslide.read_region(
(offsetx, offsety), svslevel['svslevel'],
(self.tileWidth * svslevel['scale'],
self.tileHeight * svslevel['scale']))
except openslide.lowlevel.OpenSlideError as exc:
raise TileSourceError(
'Failed to get OpenSlide region (%r).' % exc)
retries = 3
while retries > 0:
try:
tile = self._openslide.read_region(
(offsetx, offsety), svslevel['svslevel'],
(self.tileWidth * svslevel['scale'],
self.tileHeight * svslevel['scale']))
break
except openslide.lowlevel.OpenSlideError as exc:
# Reopen handle after a lowlevel error
self._openslide = openslide.OpenSlide(self._largeImagePath)
retries -= 1
if retries <= 0:
raise TileSourceError(
'Failed to get OpenSlide region (%r).' % exc)
# Always scale to the svs level 0 tile size.
if svslevel['scale'] != 1:
tile = tile.resize((self.tileWidth, self.tileHeight),
Expand Down

0 comments on commit 686025e

Please sign in to comment.