I read line by line from a named pipe that provides lines in a second-rate rhythm. I tried simple simple
for line in file:
processLine(line)
but processLine()never called. (EDIT: it is called in the end after many lines have been read, which take several minutes.) A study with the help straceshowed that the process actually makes the final system call read()every second, and is also expected to receive a full line every time.
I can simply assume that the idiom for line inbuffers the input and is called processLine()later with each line of input, probably when the buffer is full or in case the input completes (which in my case will never be).
Is it possible to explicitly point the buffer used here to something less?
Or is there another way to tune things so that each line is also processed in the second or second rhythm?
EDIT:
I am currently using this workaround:
for line in lineByLine(namedPipe):
…
And this lineByLine():
def lineByLine(openFile):
line = ''
while True:
char = os.read(openFile.fileno(), 1)
if not char:
if line:
yield line
break
line += char
if line.endswith('\n'):
yield line
line = ''
But this ugly workaround, of course, has no solution.
source
share