I noticed that if a file is being continuously written to, the file generator does not notice it:


def getLines(f):
    lines = []
    for line in f:
        lines.append(line)
    return lines

with open('/var/log/syslog', 'rb') as f:
    lines = getLines(f)
    # do some processing with lines
    # /var/log/syslog gets updated in the mean time

    # always returns an empty list, even though f has more data
    lines = getLines(f)




I found a workaround by adding f.seek(0,1) directly before the last getLines() call, but is this the expected behavior? Calling f.tell() right after the first getLines() call shows that it isn't reset back to 0. Is this correct or a bug?

--
Bill
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to