Getting total/free RAM from within Python

后端 未结 5 1818
被撕碎了的回忆
被撕碎了的回忆 2021-02-08 15:59

From within a Python application, how can I get the total amount of RAM of the system and how much of it is currently free, in a cross-platform way?

Ideally, the amount

5条回答
  •  萌比男神i
    2021-02-08 16:22

    Have you tried SIGAR - System Information Gatherer And Reporter? After install

    import os, sigar
    
    sg = sigar.open()
    mem = sg.mem()
    sg.close() 
    print mem.total() / 1024, mem.free() / 1024
    

    Hope this helps

提交回复
热议问题