Generator that produces a sequence of lines being written at the end of a file.
(filename)
| 4 | import csv |
| 5 | |
| 6 | def follow(filename): |
| 7 | ''' |
| 8 | Generator that produces a sequence of lines being written at the end of a file. |
| 9 | ''' |
| 10 | with open(filename,'r') as f: |
| 11 | f.seek(0,os.SEEK_END) |
| 12 | while True: |
| 13 | line = f.readline() |
| 14 | if line == '': |
| 15 | time.sleep(0.1) # Sleep briefly to avoid busy wait |
| 16 | continue |
| 17 | yield line |