changeset 1279:b4004739640e

fix hang-at-startup bug Ignore-this: 1ad778b512970dd9a582e7f66b93ddcd darcs-hash:20263d454f1d1b80ebe506f0cbe85f0d16ebd6aa
author drewp <drewp@bigasterisk.com>
date Sat, 20 Apr 2019 23:54:11 -0700
parents c8d05b069db3
children 87d7a14073a2
files service/rfid_pn532_py/rfid.py
diffstat 1 files changed, 6 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/service/rfid_pn532_py/rfid.py	Sat Apr 20 23:53:43 2019 -0700
+++ b/service/rfid_pn532_py/rfid.py	Sat Apr 20 23:54:11 2019 -0700
@@ -100,8 +100,11 @@
 
         self.pollPeriodSecs = .1
         self.expireSecs = 5
-        
-        task.LoopingCall(self.poll).start(self.pollPeriodSecs)
+
+        # now=False avoids a serious bug where the first read error
+        # could happen before reactor.run() is called, and then the
+        # error fails to crash the reactor and get us restarted.
+        task.LoopingCall(self.poll).start(self.pollPeriodSecs, now=False)
 
     @STATS.cardReadPoll.time()
     def poll(self):
@@ -138,6 +141,7 @@
             traceback.print_exc()
             log.error(e)
             reactor.stop()
+
     def flushOldReads(self, now):
         for uri in list(self.log):
             if self.log[uri] < now - self.expireSecs: