diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2005-06-08 16:26:34 +0000 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2005-06-08 16:26:34 +0000 |
commit | 9b8846073f9ebfc8fcff9d42cfe511a08fa14f72 (patch) | |
tree | b3a304e3f2b5070a7c26d83ea77c34cd2379f2f3 /gps.py | |
parent | 87c320a8ce17f9956643d4e2b6801bc1f79548c3 (diff) | |
download | gpsd-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-x | gps.py | 17 |
1 files changed, 16 insertions, 1 deletions
@@ -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." |