class SenderThread(threading.Thread): def __init__(self, wshandler): threading.Thread.__init__(self) self._stopevent = threading.Event() self.wshandler = wshandler self.db = DatabaseConnector() def run(self): while not self._stopevent.isSet(): self.db.connect() power = self.db.get_last("power", "value") self.wshandler.write_message(str(power)) self.db.close() self._stopevent.wait(1.5) def stop(self): self._stopevent.set()
class SenderThread(threading.Thread): def __init__(self, wshandler): threading.Thread.__init__(self) self._stopevent = threading.Event() self.wshandler = wshandler self.db = DatabaseConnector() def run(self): while not self._stopevent.isSet(): self.db.connect() power = self.db.get_last('power', 'value') self.wshandler.write_message(str(power)) self.db.close() self._stopevent.wait(1.5) def stop(self): self._stopevent.set()
class LoggerThread(threading.Thread): def __init__(self): threading.Thread.__init__(self) self._stopevent = threading.Event() self.db=DatabaseConnector() def run(self): while not self._stopevent.isSet(): self.ser=SerialConnector() self.ser.retrieve(Util.POWER_TAG) self.db.connect() self.db.update('actual_power',self.ser.get(Util.POWER_TAG)) self.db.close() self._stopevent.wait(1.0) def stop(self): self._stopevent.set()