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

Function follow

Solutions/8_2/follow.py:6–17  ·  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

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

Callers 1

ticker.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected