Skip to content

Instantly share code, notes, and snippets.

@dongbum
Created January 4, 2019 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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