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.

Revisions

  1. dongbum created this gist Jan 4, 2019.
    16 changes: 16 additions & 0 deletions Tail_on_python.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    # 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='')