Commits

Jason Scheirer  committed 3547db1

Slightly better hang handling

  • Participants
  • Parent commits faf640e

Comments (0)

Files changed (1)

File bikesniff/gpsfix.py

+import gps, time
+
 class GpsCoordinates(object):
     @property
     def coordinates(self):
 class GpsD(GpsCoordinates):
     def __init__(self, reactor):
         self.reactor = reactor
-        import gps, time
         self._gps = gps.gps()
         self._lastfix = (0., 0., time.time())
         self.reactor.callLater(1, self._update)
     def _update(self):
-        # Query
-        self._gps.query('admosy\n')
-        # See if we need to time out
-        x, y = self.coordinates if self.coordinates else (0., 0.)
-        oldx, oldy, oldtime = self._lastfix
-        age = time.time() - oldtime
-        if age > 15.:
-            self._gps = gps.gps()
-            self._lastfix = (0., 0., time.time())
-        elif (x, y) != (oldx, oldy):
-            self._lastfix = (x, y, time.time())
-        self.reactor.callLater(1, self._update)
+        try:
+            # Query
+            self._gps.query('admosy\n')
+            # See if we need to time out
+            x, y = self.coordinates if self.coordinates else (0., 0.)
+            oldx, oldy, oldtime = self._lastfix
+            age = time.time() - oldtime
+            if age > 15.:
+                self._gps = gps.gps()
+                self._lastfix = (0., 0., time.time())
+            elif (x, y) != (oldx, oldy):
+                self._lastfix = (x, y, time.time())
+        except Exception, e:
+            pass
+        finally:
+            self.reactor.callLater(1, self._update)
     @property
     def coordinates(self):
         flt, fln = self._gps.fix.latitude, self._gps.fix.longitude