Skip to content

Commit

Permalink
Cancel obsolete requests
Browse files Browse the repository at this point in the history
  • Loading branch information
m-novikov committed Jan 25, 2021
1 parent 2b55981 commit e51cc5f
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
* text=auto eol=lf
*.py eol=lf diff=python
3 changes: 3 additions & 0 deletions volumina/pixelpipeline/datasources/minmaxsource.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ def wait(self):

return self._result

def cancel(self):
self._rawRequest.cancel()


class MinMaxSource(QObject, DataSourceABC):
"""
Expand Down
3 changes: 3 additions & 0 deletions volumina/pixelpipeline/imagesources/alphamodulated.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ def __init__(self, arrayrequest, tintColor, normalize=(0, 255)):
def wait(self):
return self.toImage()

def cancel(self):
self._arrayreq.cancel()

def toImage(self):
t = time.time()

Expand Down
3 changes: 3 additions & 0 deletions volumina/pixelpipeline/imagesources/colortable.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ def __init__(self, arrayrequest, colorTable, normalize, direct=False):
def wait(self):
return self.toImage()

def cancel(self):
self._arrayreq.cancel()

def toImage(self):
t = time.time()

Expand Down
6 changes: 3 additions & 3 deletions volumina/pixelpipeline/imagesources/grayscale.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ def __init__(self, arrayrequest, normalize=None, direct=False):
def wait(self):
return self.toImage()

def cancel(self):
self._arrayreq.cancel()

def toImage(self):
t = time.time()

Expand Down Expand Up @@ -122,6 +125,3 @@ def toImage(self):
)

return img


# *******************************************************************************
4 changes: 4 additions & 0 deletions volumina/pixelpipeline/imagesources/rgba.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ def wait(self):
req.wait()
return self.toImage()

def cancel(self):
for req in self._requests:
req.cancel()

def toImage(self):
for i, req in enumerate(self._requests):
a = req.wait()
Expand Down
3 changes: 3 additions & 0 deletions volumina/pixelpipeline/imagesources/segmentationedges.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ def __init__(self, arrayreq, layer, rect, is_clickable):
self._layer = layer
self._is_clickable = is_clickable

def cancel(self):
self._arrayreq.cancel()

def wait(self):
array_data = self._arrayreq.wait()

Expand Down
5 changes: 5 additions & 0 deletions volumina/pixelpipeline/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class RequestABC(ABC):
def wait(self):
"""waits until completion and returns result"""

@abstractmethod
def cancel(self):
...


class ImageSourceABC(QABC):
"""
Expand All @@ -55,6 +59,7 @@ def setDirty(self, slicing):
pass



class PlanarSliceSourceABC(QABC):
"""
Provides a way to retrieve 2D slices of ND array
Expand Down
10 changes: 9 additions & 1 deletion volumina/tiling/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,11 @@ def __init__(self, tiling, stackedImageSources, cache_size: int = 100) -> None:
cache_size -- maximal number of encountered stacks
to cache, i.e. slices if the imagesources
draw from slicesources (default 10)
parent -- QObject
"""

QObject.__init__(self, parent=None)
self._current_requests = {}

self.tiling = tiling
self.axesSwapped = False
Expand Down Expand Up @@ -306,6 +306,7 @@ def waitForTiles(self, rectF=QRectF()):
for tile in tiles:
finished &= tile.progress >= 1.0


def requestRefresh(self, rectF, stack_id=None, prefetch=False, layer_indexes=None):
"""Requests tiles to be refreshed.
Expand All @@ -315,6 +316,12 @@ def requestRefresh(self, rectF, stack_id=None, prefetch=False, layer_indexes=Non
"""
stack_id = stack_id or self._current_stack_id
tile_nos = self.tiling.intersected(rectF)
to_cancel = self._current_requests
self._current_requests = {}

for id_, rq in to_cancel.items():
rq.cancel()

for tile_no in tile_nos:
self._refreshTile(stack_id, tile_no, prefetch, layer_indexes)

Expand Down Expand Up @@ -405,6 +412,7 @@ def _refreshTile(self, stack_id, tile_no, prefetch=False, layer_indexes=None):
try:
# Create the request object right now, from the main thread.
ims_req = ims.request(dataRect, stack_id[1])
self._current_requests[(stack_id[1], tile_no)] = ims_req
except IndeterminateRequestError:
# In ilastik, the viewer is still churning even as the user might be changing settings in the UI.
# Settings changes can cause 'slot not ready' errors during graph setup.
Expand Down

0 comments on commit e51cc5f

Please sign in to comment.