2
可能重复:
tail -f in python with no time.sleep我怎样才能阻止readline()在Python中,所以我不必投票?
我想监视正在写入(如尾-f)日志文件,我无法弄清楚如何使readline()阻塞一旦到达eof。我所有的搜索引擎都只是提出了一些解决方案,让事情不受阻碍。有没有人知道一种方式来打电话像这个块,所以我不必投票? (我完全能够轮询和睡眠的了,所以,如果你认为我要你而降低。)
fh = open('logfile')
# I only want new output, so seek to the end of the file
fh.seek(-1,2)
while True:
# I want this to block until the file has new output,
# but it sees eof and returns '' immediately
line = fh.readline()
# ... process the line
你*确实知道`tail -f`民意调查,对吗? – 2011-01-14 19:04:32
确定重复[tail -f在python中没有time.sleep](http://stackoverflow.com/questions/1475950/tail-f-in-python-with-no-time-sleep),但态度。 ..投票结束... – dawg 2011-01-14 19:56:22