pytailer icon indicating copy to clipboard operation
pytailer copied to clipboard

is this a bug?

Open allan-avatar1 opened this issue 10 years ago • 3 comments

hey, great util. thanks. i notice that in follow(self,delay=1.0) there is the following code:

            if line[-1] in self.line_terminators:
                line = line[:-1]
                if line[-1:] == '\r\n' and '\r\n' in self.line_terminators:
                    # found crlf
                    line = line[:-1]

but if this is NOT true, then that means we have a line that does not end in a line_terminator. this happens when you've reached the end of a file that you are tailing and the producer of the file is flushing midway through a line.

I would imagine you need to do the following:

            if line[-1] in self.line_terminators:
                line = line[:-1]
                if line[-1:] == '\r\n' and '\r\n' in self.line_terminators:
                    # found crlf
                    line = line[:-1]
            else:
                #Got a partial line
                trailing=True;self.seek(where);time.sleep(delay); continue

*My b if this format is annoying. I'm far too lazy to create pull requests and I have no idea how markdown works. 5min is about all the time I have committed to this bug report. Peace

allan-avatar1 avatar Jan 21 '16 18:01 allan-avatar1

Wouldn't it just wait till a new line is flushed as implemented?

six8 avatar Mar 04 '16 18:03 six8

This appears to fail in the way that jl45621 suggests.

An example that triggers the problem.

Writer: import time fout = open("/tmp/log", "w") while(True): fout.write("abcdefghijklmn") fout.flush() time.sleep(1) fout.write("opqrstuvwxyz\n") fout.flush()

Reader: import tailer import time

def process_line(line): if line != "abcdefghijklmnopqrstuvwxyz": print line

fin = open("/tmp/log", "r") tl = tailer.Tailer(fin) tl.seek_end() for line in tl.follow(0.1): process_line(line)

If this were working correctly the reader should never yield output. However it does because the tail.follow(0.1) yields partial lines that are not line terminated.

bakerkj avatar May 31 '16 02:05 bakerkj

The essential hack using this package might be

Tailer.line_terminators = []

frozflame avatar Jan 08 '17 14:01 frozflame