Skip to content

Instantly share code, notes, and snippets.

@schlady
Created February 3, 2015 15:54
Show Gist options
  • Save schlady/77e6a3ff6e9202538378 to your computer and use it in GitHub Desktop.
Save schlady/77e6a3ff6e9202538378 to your computer and use it in GitHub Desktop.
continuously stream a file line by line like 'tail -f'
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