Created
October 7, 2015 09:18
-
-
Save poros/beedc60f990386ad0484 to your computer and use it in GitHub Desktop.
Follow a file like tail -f with generators
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
def follow(thefile): | |
thefile.seek(0,2) | |
while True: | |
line = thefile.readline() | |
if not line: | |
time.sleep(0.1) | |
continue | |
yield line |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment