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 Sep 9, 2020
1 parent e66ca67 commit 7fae009
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
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
16 changes: 16 additions & 0 deletions volumina/pixelpipeline/imagesources.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,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 @@ -273,6 +276,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 Expand Up @@ -384,6 +390,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 Expand Up @@ -541,6 +550,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 Expand Up @@ -720,6 +733,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
9 changes: 9 additions & 0 deletions volumina/tiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ def __init__(
"""

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

self.tiling = tiling
self.axesSwapped = False
Expand Down Expand Up @@ -554,6 +555,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 @@ -563,6 +565,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 @@ -653,6 +661,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 7fae009

Please sign in to comment.