class Driver(QtCore.QObject): update_ui = QtCore.pyqtSignal() queue_emptied = QtCore.pyqtSignal() initialized = Bool() def check_busy(self): """ Handles writing of busy to False. Must always write to busy. """ if self.is_busy(): time.sleep(0.01) # don't loop like crazy self.busy.write(True) elif self.enqueued.read(): time.sleep(0.1) # don't loop like crazy self.busy.write(True) else: self.busy.write(False) self.update_ui.emit() @QtCore.pyqtSlot(str, list) def dequeue(self, method, inputs): """ Slot to accept enqueued commands from main thread. Method passed as qstring, inputs as list of [args, kwargs]. Calls own method with arguments from inputs. """ self.update_ui.emit() method = str(method) # method passed as qstring args, kwargs = inputs if g.debug.read(): print(self.name, ' dequeue:', method, inputs, self.busy.read()) self.enqueued.pop() getattr(self, method)(*args, **kwargs) if not self.enqueued.read(): self.queue_emptied.emit() self.check_busy() def is_busy(self): return False