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

Function follow

Solutions/8_1/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 os
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 yield line
16 else:
17 time.sleep(0.1) # Sleep briefly to avoid busy wait

Callers 1

tickerFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected