poll of filesystem
nobody at nowhere.com
Sat Jul 2 19:49:18 CEST 2011
On Sat, 02 Jul 2011 11:40:46 +0200, Belisko Marek wrote:
> just want to use poll method to get data from /proc file system. Use
> simple code for it. Problem is it seems poll return POLLIN flag but
> when I try to read data it's always empty. Could be a problem changes
> are so fast that print can't print it?
poll() doesn't work for files; they are always readable. It's meant for
pipes, sockets and character devices (ttys, etc). If you're looking for a
way to find out when a file has changed, there isn't one (Linux has
inotify, but that isn't portable and it doesn't work with /proc).
The reason why fd.read() doesn't return any data after the first call is
that you're already at EOF; you need to reset the file position with
fd.seek(0) to read more data (however: for /proc, I would recommend
closing the file and reopening it).
More information about the Python-list