I would like my python script to use all the free RAM available but no more (for efficiency reasons). I can control this by reading in only a limited amount of data but I n
Another option is the built-in Python package psutil
:
stats = psutil.virtual_memory() # returns a named tuple
available = getattr(stats, 'available')
print(available)
According to the documentation, the available
field "is calculated by summing different memory values depending on the platform and it is supposed to be used to monitor actual memory usage in a cross platform fashion."
Note the return value will be in bytes