Imitating "tail -f"

Nobody nobody at nowhere.com
Sun Nov 22 15:35:07 EST 2009


On Sun, 22 Nov 2009 03:43:31 +0100, Ivan Voras wrote:

> The problem is: poll() always returns that the fd is ready (without
> waiting), but read() always returns an empty string. Actually, it
> doesn't matter if I turn O_NDELAY on or off. select() does the same.

Regular files are always "ready" for read/write. read() might return EOF,
but it will never block (or fail with EAGAIN or EWOULDBLOCK).

> Any advice?

The Linux version of "tail" uses the Linux-specific inotify_add_watch()
mechanism to block waiting for file-modification events.

If you don't have access to inotify_add_watch(), you'll just have to keep
trying to read from the file, sleep()ing whenever you hit EOF so that you
don't tie up the system with a busy-wait.




More information about the Python-list mailing list