Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Available and used System Memory in Python? [duplicate]

Possible Duplicate:
How to get current CPU and RAM usage in Python?

How can I get the available and currently used memory from Python? It need to be cross-platform and at least work on at least Windows, Mac OS X and Linux.

I'd like to report the user in my application that he doesn't have enough memory free to proceed and do the next operation.

like image 413
Johan Dahlin Avatar asked Jul 23 '12 15:07

Johan Dahlin


People also ask

How do I check memory usage in Python?

You can use it by putting the @profile decorator around any function or method and running python -m memory_profiler myscript. You'll see line-by-line memory usage once your script exits.

How do you check the memory of a variable in Python?

Use sys. getsizeof to get the size of an object, in bytes.

What type of memory does Python use?

Python has a pymalloc allocator optimized for small objects (smaller or equal to 512 bytes) with a short lifetime. It uses memory mappings called “arenas” with a fixed size of 256 KiB.

How do I free up RAM in Python?

to clear Memory in Python just use del. By using del you can clear the memory which is you are not wanting. By using del you can clear variables, arrays, lists etc.


1 Answers

You should take a look to psutil :

>>> import psutil >>> psutil.virtual_memory() svmem(total=16717422592, available=5376126976, percent=67.8, used=10359984128, free=1831890944, active=7191916544, inactive=2325667840, buffers=525037568, cached=4000509952, shared=626225152) 
like image 97
Cédric Julien Avatar answered Oct 11 '22 10:10

Cédric Julien