From b3bea947efa55d2c0f198b6c6795b3177be27f45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Picca=20Fr=C3=A9d=C3=A9ric-Emmanuel?= Date: Wed, 6 Jan 2021 14:10:12 +0100 Subject: New upstream version 0.14.0+dfsg --- silx/gui/plot/tools/profile/manager.py | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) (limited to 'silx/gui/plot/tools/profile/manager.py') 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): -- cgit v1.2.3