Created
February 3, 2015 15:54
-
-
Save schlady/77e6a3ff6e9202538378 to your computer and use it in GitHub Desktop.
continuously stream a file line by line like 'tail -f'
This file contains 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
def filestream(file, interval=1.0): | |
with open(file) as f: | |
while True: | |
where = f.tell() | |
line = f.readline() | |
if not line: | |
time.sleep(interval) | |
f.seek(where) | |
else: | |
yield line |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment