MCPcopy Create free account
hub / github.com/dabeaz-course/practical-python / follow

Function follow

Solutions/6_7/follow.py:5–16  ·  view source on GitHub ↗

Generator that produces a sequence of lines being written at the end of a file.

(filename)

Source from the content-addressed store, hash-verified

3import time
4
5def follow(filename):
6 '''
7 Generator that produces a sequence of lines being written at the end of a file.
8 '''
9 f = open(filename, 'r')
10 f.seek(0,os.SEEK_END)
11 while True:
12 line = f.readline()
13 if line == '':
14 time.sleep(0.1) # Sleep briefly to avoid busy wait
15 continue
16 yield line
17
18# Example use
19if __name__ == '__main__':

Callers 1

follow.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected