blocking file.readlines() needed

Peter Otten __peter__ at web.de
Fri Aug 13 13:55:19 EDT 2004


Uwe Mayer wrote:

> I am looking for a way to make the call to a file objects readline()
> method 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?

The naive way to do it:

while True:
    while True:
        line = f.readline()
        if not line:
            break
        print line,
    time.sleep(1)

Peter




More information about the Python-list mailing list