Fastest way to get system uptime in Python in Linux

后端 未结 5 810
無奈伤痛
無奈伤痛 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:56

    What about:

    import subprocess
    print(subprocess.check_output(['cat', '/proc/uptime']).decode('utf-8').split()[0])
    

    Not the fastest way but simple and direct

提交回复
热议问题