According to David Beazley's talk on generators, the following code should replicate the UNIX tail -f
command:
import time
def follow(thefile):
thefile.seek(0,2)
while True:
line = thefile.readline()
if not line:
time.sleep(0.1)
continue
yield line
f = open('followed.txt')
lines = follow(f)
for i in lines:
print i
If I run this in a shell, it's doing "something", and indeed it locks up the IPython notebook, but it ain't printing out the contents of followed.txt. Why so?