Generator that produces a sequence of lines being written at the end of a file.
(filename)
| 3 | import time |
| 4 | |
| 5 | def follow(filename): |
| 6 | ''' |
| 7 | Generator that produces a sequence of lines being written at the end of a file. |
| 8 | ''' |
| 9 | try: |
| 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 |
| 18 | except GeneratorExit: |
| 19 | print('Following Done') |
| 20 | |
| 21 | def splitter(lines): |
| 22 | for line in lines: |