def run(self) -> None: logger.info("Started daemon") remove_if_exists(self.socket) server = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) server.bind(self.socket) logger.debug(f"Successfully bound {self.socket}") while True: server.listen(1) conn, addr = server.accept() msg_str = conn.recv(1024) if msg_str: params = msg_str.decode("utf-8") try: message = TimeMessageSocket(**json.loads(params)) lock.acquire() message = self.manager.process_message(message) lock.release() conn.sendall(message.encode("utf-8")) except ValueError as err: logger.exception(err) conn.sendall(str(err).encode("utf-8")) except Exception as ex: logger.exception(ex) conn.sendall(str(ex).encode("utf-8")) conn.close()
def run(self) -> None: logger.debug("Started buzzer thread.") while True: lock.acquire() alarms = self.manager.list_alarms() self.manager.cleanup() lock.release() if len(alarms) > 0: now = datetime.now().time().replace(second=0, microsecond=0) alarm = alarms[0] if alarm.time == now: lock.acquire() if (not self.manager.is_canceled(alarm.time, alarm.when) and self.manager.alarm_pid is None): self.manager.alarm_pid = self.start_alarm() lock.release() sleep(10)
def finalize(self) -> None: lock.acquire() self.manager.cleanup() self.manager.dump_alarms() lock.release()