Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is this a bug? #9

Open
allan-avatar1 opened this issue Jan 21, 2016 · 3 comments
Open

is this a bug? #9

allan-avatar1 opened this issue Jan 21, 2016 · 3 comments

Comments

@allan-avatar1
Copy link

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

@six8
Copy link
Owner

six8 commented Mar 4, 2016

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

@bakerkj
Copy link

bakerkj commented May 31, 2016

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.

@frozflame
Copy link

The essential hack using this package might be

Tailer.line_terminators = []

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants