Created
January 4, 2019 06:59
-
-
Save dongbum/c8785313d3336bf21c23d45fca0c28c7 to your computer and use it in GitHub Desktop.
Tail on python (without external library)
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
# 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