How to get current CPU and RAM usage in Python?

前端 未结 16 1907
攒了一身酷
攒了一身酷 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:58

    Only for Linux: One-liner for the RAM usage with only stdlib dependency:

    import os
    tot_m, used_m, free_m = map(int, os.popen('free -t -m').readlines()[-1].split()[1:])
    

    edit: specified solution OS dependency

提交回复
热议问题