blocking file.readlines() needed

CptPicard jpmorichon at
Fri Aug 13 19:16:29 CEST 2004

Geoff Howland has written a script,, that should give you some
hints on how to do your "tail -f".

Using google, I also found some talks about that. Here is one of the
solution that I found :

import sys,os
import time
from Tkinter import *
from ScrolledText import ScrolledText

class LogViewer(Frame):
    def __init__(self, parent, filename):
        self.filename = filename
        self.file = open(filename, 'r')
        self.text = ScrolledText(parent)
        data =
        self.size = len(data)
        self.text.insert(END, data)
        self.after(100, self.poll)

    def poll(self):
        if os.path.getsize(self.filename) > self.size:
            data =
            self.size = self.size + len(data)
            self.text.insert(END, data)

if __name__ == "__main__":
    root = Tk()
    viewer = LogViewer(root, sys.argv[1])

"Uwe Mayer" <merkosh at> wrote in message
news:cfiqlr$3a8$1 at
> Hi,
> I am looking for a way to make the call to a file objects readline()
> blocking when there is no more data, until data is appended to the file,
> similar to the way
> $ tail -F <system log file>
> works.
> However, file.readlines() aborts and returns an empty list.
> Any ideas?
> Thanks
> Ciao
> Uwe

More information about the Python-list mailing list