System idle time under Linux

John Pinner funthyme at
Thu Sep 30 11:26:23 CEST 2010

On Sep 29, 7:36 pm, Hugo Léveillé <hu... at> wrote:
> Good point
> One I am looking for, is time since last user mouse or keyboard action.
> So I guess I am looking for the exact same thing a screensaver is
> looking for

The command

who -Hu).

will give you idle time for each logged-in user

( H - print headers; u - list users )

and you could run this command via subprocess, then read and parse its

Alternatively you could parse the same file(s) as who - I think it
reads /var/run/utmp - but that would be a lot more work, as it is a
binary file (run man utmp to see its format, use the struct module to

Best wishes,


More information about the Python-list mailing list