gpsd-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [gpsd-users] Flush unconsumed GPS reports in Python


From: Alex
Subject: Re: [gpsd-users] Flush unconsumed GPS reports in Python
Date: Wed, 20 Dec 2017 10:16:11 +0000

Hi Gary, thank you for the reply.

I understand the logic of what you say and it was my intention to implement something like that. However, given that this is probably a common scenario - I was wondering if I wouldn't be reinventing the bicycle, and if there are existing solutions to this problem.


I am guessing there are none, so I wrote this, with the intention of calling this function every time I need a fresh report. It clears the queue, then I can call my regular read function:

def flush_gps(self):
    '''Clear every unread report in the GPS buffer, by reading
    everything that is there, until we get a StopIteration
    exception'''
    logger.debug('Starting GPS report flushing')
    unconsumed = 0
    while True:
        try:
            self.gps_session.next()
            unconsumed += 1
        except StopIteration:
            break
    logger.debug('GPS flushed unconsumed %i reports', unconsumed)



This doesn't give me the expected result though. I see `Starting GPS report flushing` in the log, but it seems that the StopIteration exception is never raised, so the loop never breaks.

1. Is it possible that the speed at which new reports are received is much higher than the speed at which they are consumed?  (even without any `sleep` calls inside the loop??!)
2. Is the assumption that StopIteration will be raised correct? I've seen that in the code of the library: https://github.com/ukyg9e5r6k7gubiekd6/gpsd/blob/master/gps/gps.py#L312

Here is the relevant excerpt

def next(self):
if self.read() == -1:
raise StopIteration
if hasattr(self, "data"):
return self.data
else:
return self.response



This is somewhat puzzling, because as you said - it shouldn't be a complicated matter.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]