def resume(self, ): if self.RE.state == 'paused': self.threadfuture = threads.QThreadFuture( self.RE.resume, threadkey='RE', showBusy=True, finished_slot=self.sigFinish.emit) self.threadfuture.start() self.sigResume.emit()
def test_threads(qtbot): from xicam.core import threads from qtpy.QtCore import QObject, Signal def callback(a): assert a == 10 t = threads.QThreadFuture(sum, [1, 2, 3, 4], callback_slot=callback) class Callback(QObject): sig = Signal(int) callback = Callback() t2 = threads.QThreadFuture(sum, [1, 2, 3, 4], callback_slot=callback.sig) t.start() t2.start() qtbot.waitSignals([t.sigFinished, t2.sigFinished])
def run(self, q, I, callback_slot=None): if callback_slot is None: callback_slot = lambda t: None self.update_model() key = self.fitterbox.currentText() fitting_method = self.fitters[key]() thread = threads.QThreadFuture( fitting_method, self.fittable, q, I, callback_slot=lambda t: callback_slot(self.update(t))) thread.start() return thread
def setPassive(self, passive): if self.thread: self.thread.cancel() self.thread = None if passive: update_action = self.updateFrame else: update_action = self.device.trigger self.thread = threads.QThreadFuture(self._update_thread, update_action, showBusy=False, except_slot=lambda ex: self.device.unstage()) self.thread.start()
def _test(self): from xicam.core import threads import time def test(): a = 0 for i in range(10): a += 1 time.sleep(1) for i in range(100): t = threads.QThreadFuture(test) t.start()
def test_threads(): from qtpy.QtWidgets import QApplication app = QApplication([]) from xicam.core import threads from qtpy.QtCore import QTimer, QObject, Signal q = QTimer() def callback(a): assert a == 10 t = threads.QThreadFuture(sum, [1, 2, 3, 4], callback_slot=callback) class Callback(QObject): sig = Signal(int) callback = Callback() t2 = threads.QThreadFuture(sum, [1, 2, 3, 4], callback_slot=callback.sig) q.singleShot(1000, t.start) q.singleShot(1000, t2.start) q.singleShot(2000, app.quit) app.exec_()
def test_exit_before_thread(qtbot): from xicam.core import threads import time from qtpy.QtWidgets import QMainWindow window = QMainWindow() def long_thread(): time.sleep(100000) for i in range(1000): t = threads.QThreadFuture(long_thread) t.start() time.sleep(.01) window.deleteLater()
def start_show_results(self): self.last_results_thread = threads.QThreadFuture(self.show_results) self.last_results_thread.start()