def requestUpdateProfile(self, profileRoi): """Request to update a specific profile ROI. :param ~core.ProfileRoiMixIn profileRoi: """ if profileRoi.computeProfile is None: return threadPool = silxGlobalThreadPool() # Clean up deprecated runners for runner in list(self._pendingRunners): if not inspect.isValid(runner): self._pendingRunners.remove(runner) continue if runner.getRoi() is profileRoi: if threadPool.tryTake(runner): self._pendingRunners.remove(runner) item = self.getPlotItem() if item is None or not isinstance(item, profileRoi.ITEM_KIND): # This item is not compatible with this profile profileRoi._setPlotItem(None) profileWindow = profileRoi.getProfileWindow() if profileWindow is not None: profileWindow.setProfile(None) return profileRoi._setPlotItem(item) runner = _RunnableComputeProfile(threadPool, item, profileRoi) runner.runnerFinished.connect(self.__cleanUpRunner) runner.resultReady.connect(self.__displayResult) self._pendingRunners.append(runner) threadPool.start(runner)
def testSaturateThreadPool(self): button = ThreadPoolPushButton() button.setCallable(self._trace, "a", 100) number = qt.silxGlobalThreadPool().maxThreadCount() * 2 for _ in range(number): button.executeCallable() self.waitForPendingOperations(button) self.assertListEqual(self._result, ["a"] * number)
def testSaturateThreadPool(self): button = ThreadPoolPushButton() button.setCallable(self._trace, "a", 100) number = qt.silxGlobalThreadPool().maxThreadCount() * 2 for _ in range(number): button.executeCallable() self.waitForPendingOperations(button) self.assertListEqual(self._result, ["a"] * number)
def testFromQtThread(self): """Call submitToQtMainThread from a Qt thread pool""" class Runner(qt.QRunnable): def __init__(self, fn): super(Runner, self).__init__() self._fn = fn def run(self): self._fn() def autoDelete(self): return True threadPool = qt.silxGlobalThreadPool() runner = Runner(self._threadedTest) threadPool.start(runner) for i in range(100): # Loop over for 10 seconds self.qapp.processEvents() done = threadPool.waitForDone(100) if done: break else: self.fail('Thread pool task still running')
def testFromQtThread(self): """Call submitToQtMainThread from a Qt thread pool""" class Runner(qt.QRunnable): def __init__(self, fn): super(Runner, self).__init__() self._fn = fn def run(self): self._fn() def autoDelete(self): return True threadPool = qt.silxGlobalThreadPool() runner = Runner(self._threadedTest) threadPool.start(runner) for i in range(100): # Loop over for 10 seconds self.qapp.processEvents() done = threadPool.waitForDone(100) if done: break else: self.fail('Thread pool task still running')