From 8a35b8b8843eb9dc9cdd0b0d5b6a42c32a38f159 Mon Sep 17 00:00:00 2001 From: Ondrej Mikle Date: Sun, 29 Oct 2017 16:04:24 +0100 Subject: [PATCH] Warning about open-switch thread not working properly --- brmdoor_nfc.config.sample | 3 ++- brmdoor_nfc_daemon.py | 14 ++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/brmdoor_nfc.config.sample b/brmdoor_nfc.config.sample index 8681ff9..7eef831 100644 --- a/brmdoor_nfc.config.sample +++ b/brmdoor_nfc.config.sample @@ -46,9 +46,10 @@ reconnect_delay = 300 # Controls showing status of "OPEN/CLOSE" switch that is connected to some GPIO pin # Changes topic of connected IRC channels if IRC is enabled # There is no point in enabling this if you disabled IRC +# Not yet usable - do not use because of GIL and python-irc not retrieving topic from channel # enabled - True/False # status_file - file in sysfs that contains 1 or 0 defining the state of button # open_value - which value in status_file respresents the switch being in "OPEN" position, 1 character -enabled = True +enabled = False status_file = /sys/class/gpio/gpio11/value open_value = 1 diff --git a/brmdoor_nfc_daemon.py b/brmdoor_nfc_daemon.py index dbed511..628560d 100755 --- a/brmdoor_nfc_daemon.py +++ b/brmdoor_nfc_daemon.py @@ -120,7 +120,8 @@ class NFCScanner(object): self.actOnUid(uid_hex) else: #prevent busy loop if reader goes awry - time.sleep(0.3) + e = threading.Event() + e.wait(timeout=0.3) except NFCError, e: #this exception happens also when scanUID times out logging.debug("Failed to wait for RFID card: %s", e) @@ -177,8 +178,9 @@ class NFCScanner(object): logging.info("Unknown UID %s", uid_hex) self.sendIrcMessage("Denied unauthorized card") - time.sleep(self.unknownUidTimeoutSecs) - + e = threading.Event() + e.wait(timeout=self.unknownUidTimeoutSecs) + class IrcThread(threading.Thread): """ Class for showing messages about lock events and denied/accepted cards @@ -318,6 +320,7 @@ class OpenSwitchThread(threading.Thread): if self.ircThread.connected: for channel in self.ircThread.channels: + #TODO: this always returns None, don't know why topic = self.ircThread.getTopic(channel) if not topic or not re.match(r"^\s*(OPEN|CLOSED) \|", topic): newTopic = strStatus @@ -329,9 +332,8 @@ class OpenSwitchThread(threading.Thread): pass #silently ignore non-existent file and other errors, otherwise it'd spam log except Exception: logging.exception("Exception in open switch thread") - logging.info("Before sleep") - time.sleep(1) - logging.info("After sleep") + e = threading.Event() + e.wait(timeout=1) if __name__ == "__main__":