Following a file, or cloning tail

Cameron Laird claird at starbase.neosoft.com
Wed Jun 28 17:32:43 EDT 2000


In article <8jdj3t$or4$1 at news1.xs4all.nl>,
Boudewijn Rempt <boud at rempt.xs4all.nl> wrote:
>I'm trying to write an application that follows the output of another
>app, analyzes it, and serves it up as html. Kind of filtering tail,
>really. Is there any accepted 'best' way of 'tailing' a file?
>
>I thought about having two threads, one doing the tailing, one
>doing the servering (instantiating new threads as needed), but I
>can't even get the tailing right!
			.
			.
			.
This is the platform-neutral way to do it:  open the file
for reading.  Read to the end.  Idle (whether by an event-
or thread-oriented mechanism).  Poll for new content, as
explained below.  Read to end (possibly with some seek()ing
and find()ing, depending on details of your algorithm).
Idle.  Repeat.

Some observers gag at the thought of polling.  That's part
of the robustness of our contemporary file-systems, though:
the reliable way to find out what's in them is to ask.

How do you check for new content?  Among the possibilities
are
1.  Read to end.  You're polling anyway (presumably
    at a frequency of a few hertz), so there's no
    particular harm in this.
2.  Check the size of the file for a change.

Do you want code, also?  I assume that, if I'm only available
for one of them today, you'd prefer the *idea*.
-- 

Cameron Laird <claird at NeoSoft.com>
Business:  http://www.Phaseit.net
Personal:  http://starbase.neosoft.com/~claird/home.html



More information about the Python-list mailing list