summaryrefslogtreecommitdiff
path: root/gps.py
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2005-06-08 16:26:34 +0000
committerEric S. Raymond <esr@thyrsus.com>2005-06-08 16:26:34 +0000
commit9b8846073f9ebfc8fcff9d42cfe511a08fa14f72 (patch)
treeb3a304e3f2b5070a7c26d83ea77c34cd2379f2f3 /gps.py
parent87c320a8ce17f9956643d4e2b6801bc1f79548c3 (diff)
downloadgpsd-9b8846073f9ebfc8fcff9d42cfe511a08fa14f72.tar.gz
Python library has thread support.
gpsfake has -p option that dumps r and w reports to standard output; this will support regression testing.
Diffstat (limited to 'gps.py')
-rwxr-xr-xgps.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/gps.py b/gps.py
index 69b7448f..12c92add 100755
--- a/gps.py
+++ b/gps.py
@@ -2,7 +2,7 @@
#
# gps.py -- Python interface to GPSD.
#
-import time, calendar, socket, sys
+import time, calendar, socket, sys, thread
from math import *
ONLINE_SET = 0x000001
@@ -168,6 +168,8 @@ class gps(gpsdata):
self.connect(host, port)
self.verbose = verbose
self.raw_hook = None
+ self.thread_hook = None
+ self.thread_id = None
def connect(self, host, port):
"""Connect to a host on a given port.
@@ -209,6 +211,17 @@ class gps(gpsdata):
def set_raw_hook(self, hook):
self.raw_hook = hook
+ def __thread_poll(self):
+ while True:
+ st = self.poll()
+ if st == -1:
+ break
+ thread.exit()
+
+ def set_thread_hook(self, hook):
+ self.thread_hook = hook
+ self.thread_id = thread.start_new_thread(self.__thread_poll, ())
+
def __del__(self):
if self.sock:
self.sock.close()
@@ -364,6 +377,8 @@ class gps(gpsdata):
self.timings.collect(*data.split())
if self.raw_hook:
self.raw_hook(buf);
+ if self.thread_hook:
+ self.thread_hook(buf);
def poll(self):
"Wait for and read data being streamed from gpsd."