def _mainloop(self): terminal = Terminal() if not terminal.is_open(): self.notify.emit(u'Ошибка', u'Нет связи с концентратором') self.ready.emit(False, {}) return if self.db is None: self.db = DB(notify=lambda title, msg: self.notify.emit(title, msg)) titles = self.db.get_terminals() devices = titles.keys() if not devices: self.notify.emit(u'Ошибка', u'Нет информации о терминалах') self.ready.emit(False, {}) return self.queue = Queue() self.ready.emit(True, titles) greenlets = self.spawn_device_greenlets(terminal, devices) while True: command = self.queue.get() if callable(command): command(terminal) else: [greenlet.kill() for greenlet in greenlets] break terminal.close() self.queue = None self.stopped.emit()
def _mainloop(self): try: terminal = Terminal(explicit_error=True) except ReaderError: self.notify.emit(_('Terminals error'), _('Cannot connect to concentrator')) self.ready.emit(False, {}) sleep(10) self.stopped.emit() return self.db = DB(notify=lambda title, msg: self.notify.emit(title, msg)) self.queue = Queue() self.ready.emit(True, self.devices) greenlets = self.spawn_device_greenlets(terminal, self.devices) if not greenlets: greenlets.append(spawn(self.dummy_greenlet)) while True: command = self.queue.get() if callable(command): command(terminal) else: [greenlet.kill() for greenlet in greenlets] break terminal.close() self.queue = None self.stopped.emit()