Getting total/free RAM from within Python

Algorias picture Algorias · Jul 30, 2009 · Viewed 10k times · Source

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 of free RAM should consider only physical memory that can actually be allocated to the Python process.

Answer

sunqiang picture sunqiang · Jul 30, 2009

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