Skip to content

Instantly share code, notes, and snippets.

@dongbum
Created January 4, 2019 06:59
Show Gist options
  • Save dongbum/c8785313d3336bf21c23d45fca0c28c7 to your computer and use it in GitHub Desktop.
Save dongbum/c8785313d3336bf21c23d45fca0c28c7 to your computer and use it in GitHub Desktop.
Tail on python (without external library)
# https://stackoverflow.com/a/53121178/8793092
def follow(thefile):
while True:
line = thefile.readline()
if not line:
time.sleep(0.1)
continue
yield line
if __name__ == '__main__':
logfile = open("run/foo/access-log","r")
loglines = follow(logfile)
for line in loglines:
print(line, end='')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment