summaryrefslogtreecommitdiff
path: root/silx/gui/plot/tools/profile/manager.py
diff options
context:
space:
mode:
Diffstat (limited to 'silx/gui/plot/tools/profile/manager.py')
-rw-r--r--silx/gui/plot/tools/profile/manager.py31
1 files changed, 23 insertions, 8 deletions
diff --git a/silx/gui/plot/tools/profile/manager.py b/silx/gui/plot/tools/profile/manager.py
index 4d467f0..757b741 100644
--- a/silx/gui/plot/tools/profile/manager.py
+++ b/silx/gui/plot/tools/profile/manager.py
@@ -76,6 +76,17 @@ class _RunnableComputeProfile(qt.QRunnable):
self._signals.moveToThread(threadPool.thread())
self._item = item
self._roi = roi
+ self._cancelled = False
+
+ def _lazyCancel(self):
+ """Cancel the runner if it is not yet started.
+
+ The threadpool will still execute the runner, but this will process
+ nothing.
+
+ This is only used with Qt<5.9 where QThreadPool.tryTake is not available.
+ """
+ self._cancelled = True
def autoDelete(self):
return False
@@ -106,12 +117,13 @@ class _RunnableComputeProfile(qt.QRunnable):
def run(self):
"""Process the profile computation.
"""
- try:
- profileData = self._roi.computeProfile(self._item)
- except Exception:
- _logger.error("Error while computing profile", exc_info=True)
- else:
- self.resultReady.emit(self._roi, profileData)
+ if not self._cancelled:
+ try:
+ profileData = self._roi.computeProfile(self._item)
+ except Exception:
+ _logger.error("Error while computing profile", exc_info=True)
+ else:
+ self.resultReady.emit(self._roi, profileData)
self.runnerFinished.emit(self)
@@ -815,8 +827,11 @@ class ProfileManager(qt.QObject):
self._pendingRunners.remove(runner)
continue
if runner.getRoi() is profileRoi:
- if threadPool.tryTake(runner):
- self._pendingRunners.remove(runner)
+ if hasattr(threadPool, "tryTake"):
+ if threadPool.tryTake(runner):
+ self._pendingRunners.remove(runner)
+ else: # Support Qt<5.9
+ runner._lazyCancel()
item = self.getPlotItem()
if item is None or not isinstance(item, profileRoi.ITEM_KIND):