I have a python script which is reading a continuously updated log file line by line. During some instances the function is reading a single line as three lines.
Below is the function which is reading the log file continuously.
def follow(thefile):
print("stilllll")
thefile.seek(0, 2)
while True:
#time.sleep(0.1)
line = thefile.readline()
if not line:
time.sleep(0.1)
continue
yield line
Below code is for calling this function from main.
if __name__ == '__main__':
logfile = codecs.open("log.txt", "r", encoding='utf-8',errors='ignore')
loglines = follow(logfile)
for line in loglines:
Below is how logging is happening and log.txt is the file which is being written and read.
cat my1.fifo | telnet 172.27.172.247 10031 &> log.txt &
The below is the screenshot of line which was read as three lines.
It read it as three lines like this
0.0
[sudo] password
0.1643835616438356
for olta
0.09230769230769231
usr:
0.06451612903225806
What could be the reason for it ?
I tried to change the way it is reading the log file but since it is happening only some times then it is difficult to reproduce.