(python 2.7.9 on raspbian on raspberry hardware) Reading GPS data from a serial port, I find no way to defeat input buffering. This makes my data come in big blurbs with far too much time in between. I searched this site, and others, and applied "buffering" in various forms (buffering=0, buffering=-1, buffering=5, ... ) on the open statement, all to no avail.
INPORT='/dev/ttyAMA0'
with open(INPORT,'rb',buffering=-1) as infile:
for INLIN in INFILE:
INFIELD=INLIN.split(",")
if INFIELD[0][0:1] == "$":
print datetime.datetime.now(),INFIELD[0]
sample of output:
2016-04-17 11:59:20.469383 $GNGSA
2016-04-17 11:59:20.471004 $GPGSV
2016-04-17 11:59:20.472660 $GPGSV
2016-04-17 11:59:20.475128 $GPGSV
2016-04-17 11:59:20.475743 $GPGSV
2016-04-17 11:59:20.477228 $GLGSV
2016-04-17 11:59:20.478902 $GLGSV
2016-04-17 11:59:20.480494 $GLGSV
2016-04-17 11:59:20.481994 $GNGLL
2016-04-17 11:59:20.483569 $GNRMC
2016-04-17 11:59:20.484283 $GNVTG
2016-04-17 11:59:33.681551 $GNGGA
2016-04-17 11:59:33.682010 $GNGSA
2016-04-17 11:59:33.682357 $GNGSA
2016-04-17 11:59:33.682693 $GPGSV
2016-04-17 11:59:33.683025 $GPGSV
2016-04-17 11:59:33.683359 $GPGSV
2016-04-17 11:59:33.683680 $GPGSV
2016-04-17 11:59:33.684017 $GLGSV
2016-04-17 11:59:33.684467 $GLGSV
for INLIN iter(infile.readline,"")for INLIN in iter(infile.readline,"")