Tailing a log file?
sjdevnull at yahoo.com
sjdevnull at yahoo.com
Fri Jun 22 16:33:03 EDT 2007
On Jun 22, 2:50 pm, "Kenji Noguchi" <tokyo... at gmail.com> wrote:
> something like this? unix tail command does more fancy stuff
> like it waits for timeout, and check if the file is truncated
> or depending on incoming data it sleeps seconds , etc etc.
>
> #!/usr/bin/env python
> import sys, select
>
> while True:
> ins, outs, errs = select.select([sys.stdin],[],[])
> for i in ins:
> print i.readline()
select doesn't work on regular files (only pipes/sockets/etc).
inotify is platform-specific; the portable way to do this is to poll,
like tail does. If you know you're on a platform that has inotify or
something like it, it's probably the more efficient (and lower
latency) route to go.
More information about the Python-list
mailing list