select.poll.poll() never blocks
david.birdsong at gmail.com
Thu Feb 12 07:09:11 CET 2009
On Feb 11, 7:47 pm, "Rhodri James" <rho... at wildebst.demon.co.uk>
> On Thu, 12 Feb 2009 03:01:16 -0000, birdsong <david.birds... at gmail.com>
> > So I guess I didn't have a complete understanding of poll, I thought
> > it returned file descriptors that had registered an event that the
> > user asked to watch for. In my case, select.POLLIN
> > Constant Meaning
> > POLLIN There is data to read
> > ...there ins't any data to be read. The file is readable, yes, but is
> > that all that the syscall has to offer?
> To quote the web page referenced in help(select):
> "It cannot be used on regular files to determine whether a file has grown
> since it was last read."
> poll() and friends are wrappers over the socket library "poll" and
> "select" functions, which primarily exist to facilitate asynchronous
> socket communications. They can take ordinary file descriptors as
> well as sockets because there's no good reason not to, but a regular
> file will always be ready to read as long as you haven't read past
> the end of file.
> You're trying to use a regular file as if it was a pipe. My first
> obvious question is do you have to do it this way? Do you have
> any control over the program writing to file? Can you cause the
> output to go to stdout and pipe it into your script's stdin
> instead? That would make your life vastly easier.
agreed, this was my original idea, but i figured implementing a tail -
f via poll was alot faster to write and implement. i'm glad at least
know why it wasn't working as expected.
i've already written a tail -f similar to the one found in the link
from a later poster, but i was hoping to use poll to cut down on
unecessary seeks -i'm trying to avoid actions that would drive up
iowait on the boxes this would run on.
thanks for the clarification on the poll family of syscalls.
> If you can't, I'm not sure what your best strategy is. I'd
> be tempted to use "tail -f filetocheck | yourscript.py" and
> palm the job off on an already-written tool. If you want to
> do it in Python, the only thing that springs to mind is
> periodically checking the size of the file and reading more
> when that changes. You'll need to be very careful to keep
> what size you think the file is in sync with how much you've
> Rhodri James *-* Wildebeeste Herder to the Masses
More information about the Python-list