Possible File iteration bug

Billy Mays noway at nohow.com
Thu Jul 14 21:46:26 CEST 2011

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:
     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?


More information about the Python-list mailing list