diff server/utils.py @ 24:44c5ab5ea879

- some fixes for server code - don't turn off bluetooth in avr code
author Matt Johnston <matt@ucc.asn.au>
date Wed, 06 Jun 2012 22:32:49 +0800
parents b5925cb4f264
children 2943f62c8e62
line wrap: on
line diff
--- a/server/utils.py	Mon Jun 04 23:50:42 2012 +0800
+++ b/server/utils.py	Wed Jun 06 22:32:49 2012 +0800
@@ -4,6 +4,12 @@
 import time
 import select
 
+lightblue = None
+try:
+    import lightblue
+except ImportError:
+    pass
+
 DEFAULT_TRIES = 3
 READLINE_SELECT_TIMEOUT = 20
 
@@ -57,13 +63,17 @@
 def readline(sock):
     timeout = READLINE_SELECT_TIMEOUT
     buf = ''
-    while true:
-        (rlist, wlist, xlist) = select.select([sock], [], [], timeout)
-        if sock not in rlist:
-            # hit timeout
-            return None
+    while True:
+        if not lightblue:
+            (rlist, wlist, xlist) = select.select([sock], [], [], timeout)
+            if sock not in rlist:
+                # hit timeout
+                return None
 
         c = sock.recv(1)
+        if c == '':
+            # lightblue timeout
+            return None
         if c == '\r':
             continue