Fastest way to get system uptime in Python in Linux

后端 未结 5 851
無奈伤痛
無奈伤痛 2021-01-11 10:24

I\'m looking for a fast and lightweight way to read system uptime from a Python script. Is there a way to call the sysinfo Linux system call from Python?

<
5条回答
  •  耶瑟儿~
    2021-01-11 10:54

    Adding an UP TO DATE answer.

    This may not be the fastest way. But this is should be the replacement for psutil.boot_time() since I couldn't find boot_time in latest versions of linux psutil lib.

    Dependancy:

    pip3 install uptime
    

    Usage:

    >>> from uptime import uptime
    >>> uptime()
    49170.129999999997
    

    More info

提交回复
热议问题