pvl.irker-syslog: fix not-polling on irk
authorTero Marttila <terom@paivola.fi>
Sun, 13 Jan 2013 02:16:36 +0200
changeset 121 4f16bf6365f1
parent 120 d342506c3ef3
child 122 f742c866c765
pvl.irker-syslog: fix not-polling on irk
bin/pvl.irker-syslog
pvl/irk.py
--- a/bin/pvl.irker-syslog	Sun Jan 13 02:16:12 2013 +0200
+++ b/bin/pvl.irker-syslog	Sun Jan 13 02:16:36 2013 +0200
@@ -98,28 +98,28 @@
             else :
                 print tag, text
 
-        # only poll if we have something to poll
-        if syslog.poll :
-            # can we poll irk?
-            if irker.irk.recv :
-                reading = (irker.irk, )
-            else :
-                reading = ()
-            
-            poll = syslog.select(syslog.poll, reading=reading) or () # timeout -> ()
-
-        else :
+        # quit unless we have something to poll
+        if not syslog.poll :
             break
 
-        # irks?
-        try :
-            for msg in irker.irk :
-                log.info("irk: %s", msg)
+        # is irk pollable?
+        if irker.irk.recv :
+            reading = (irker.irk, )
+        else :
+            reading = ()
+        
+        poll = syslog.select(syslog.poll, reading=reading) or () # timeout -> ()
+        
+        if irker.irk in poll :
+            # irks?
+            try :
+                for msg in irker.irk :
+                    log.info("irk: %s", msg)
 
-        except EOFError :
-            # exit
-            log.error("irk: EOF")
-            return 1
+            except EOFError :
+                # exit
+                log.error("irk: EOF")
+                return 1
        
     # done
     log.info("Exiting...")
--- a/pvl/irk.py	Sun Jan 13 02:16:12 2013 +0200
+++ b/pvl/irk.py	Sun Jan 13 02:16:36 2013 +0200
@@ -100,6 +100,10 @@
             Yield JSON inputs from source.
         """
 
+        if not self.recv :
+            # never going to be anything
+            return
+
         for line in self.recv :
             # XXX: error handling?
             yield json.loads(line)