Skip to content

Commit

Permalink
Retry read_region if openslide reports an error
Browse files Browse the repository at this point in the history
  • Loading branch information
manthey committed Feb 1, 2024
1 parent 6e5394b commit 0eb98cb
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:

Check warning on line 308 in sources/openslide/large_image_source_openslide/__init__.py

View check run for this annotation

Codecov / codecov/patch

sources/openslide/large_image_source_openslide/__init__.py#L308

Added line #L308 was not covered by tests
# Reopen handle after a lowlevel error
self._openslide = openslide.OpenSlide(self._largeImagePath)
retries -= 1

Check warning on line 311 in sources/openslide/large_image_source_openslide/__init__.py

View check run for this annotation

Codecov / codecov/patch

sources/openslide/large_image_source_openslide/__init__.py#L310-L311

Added lines #L310 - L311 were not covered by tests
if retries <= 0:
raise TileSourceError(

Check warning on line 313 in sources/openslide/large_image_source_openslide/__init__.py

View check run for this annotation

Codecov / codecov/patch

sources/openslide/large_image_source_openslide/__init__.py#L313

Added line #L313 was not covered by tests
'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 0eb98cb

Please sign in to comment.