hpcloud/tail

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

ailisp opened this issue · 0 comments

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.