poll of filesystem

Tim Roberts timr at probo.com
Sat Jul 2 18:37:55 EDT 2011


Belisko Marek <marek.belisko at gmail.com> 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 make sense here.  The data in /proc/loadavg data is not text
data that gets updated periodically.  There is no file on disk somewhere
called /proc/loadavg.  Instead, reading /proc/loadavg causes a call into a
kernel driver, and reads data directly from variables stored in the kernel.
The data is ALWAYS available.

If you want the data once a second, just do it the easy way:

    import time
    while True:
        print open('/proc/loadavg').read()
        time.sleep(1)
-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the Python-list mailing list