Getting total/free RAM from within Python

后端 未结 5 1698
被撕碎了的回忆
被撕碎了的回忆 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条回答
  •  北荒
    北荒 (楼主)
    2021-02-08 16:33

    psutil would be another good choice. It also needs a library installed however.

    >>> import psutil
    >>> psutil.virtual_memory()
    vmem(total=8374149120L, available=2081050624L, percent=75.1,
         used=8074080256L, free=300068864L, active=3294920704,
         inactive=1361616896, buffers=529895424L, cached=1251086336)
    

提交回复
热议问题