Determine free RAM in Python

后端 未结 5 1509

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

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-15 08:35

    I suppose you could use free (http://www.cyberciti.biz/faq/linux-check-memory-usage/), ps or maybe the MemoryMonitor class from the SO-thread posted at the very bottom of my answer to do this. Just cut some slack and leave some small amount of ram unused for other processes if they should need it urgently yo avoid disk writes on their behalf.

    You will need to parse the output from free or ps if you use that, but that shouldn't be hard. Remember that you need to analyze available ram real time, so you can adjust if another process gets memory hungry for some reason.

    also see this thread: How to get current CPU and RAM usage in Python?

提交回复
热议问题