poros
10/7/2015 - 9:18 AM

Follow a file like tail -f with generators

Follow a file like tail -f with generators

import time

def follow(thefile):
    thefile.seek(0,2)
    while True:
        line = thefile.readline()
        if not line:
            time.sleep(0.1)
            continue
        yield line