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??!)
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.