How to get current CPU and RAM usage in Python?

前端 未结 16 1821
攒了一身酷
攒了一身酷 2020-11-22 04:09

What\'s your preferred way of getting current system status (current CPU, RAM, free disk space, etc.) in Python? Bonus points for *nix and Windows platforms.

There s

16条回答
  •  爱一瞬间的悲伤
    2020-11-22 04:56

    You can use psutil or psmem with subprocess example code

    import subprocess
    cmd =   subprocess.Popen(['sudo','./ps_mem'],stdout=subprocess.PIPE,stderr=subprocess.PIPE) 
    out,error = cmd.communicate() 
    memory = out.splitlines()
    

    Reference http://techarena51.com/index.php/how-to-install-python-3-and-flask-on-linux/

    https://github.com/Leo-g/python-flask-cmd

提交回复
热议问题