hpcloud / tail

Go package for reading from continously updated files (tail -f)
MIT License
2.7k stars 502 forks source link

waiting for file to appear doesn't appear if file isn't closed #164

Open ailisp opened 4 years ago

ailisp commented 4 years ago

When doing this on an inexist file:

tail.TailFile(outputFilename, tail.Config{
            Follow: true, ReOpen: true, MustExist: false,
})

It logs waiting for file to appear. If i create the file now in a text editor, enter some lines and save, tail correctly detect there are new lines. However, if the file is created by another program and not closed, for example, this python script:

with open(outputFilename, 'w') as f:
    for i in range(100):
        f.write(str(i))
        f.write('\n')
        f.flush()
        time.sleep(1)

Then the tail doesn't detect file exist before the file is closed. But the file content does changed before it's closed. I can verify by 1) open the file in a text editor; or 2) rerun the go tail program, this time it can watch the file line by line.