从 Python 中获取总内存/空闲内存 [英] Getting total/free RAM from within Python

查看:35
本文介绍了从 Python 中获取总内存/空闲内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Python 应用程序中以跨平台方式获取系统的 RAM 总量以及当前可用的 RAM 总量?

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?

理想情况下,空闲 RAM 量应仅考虑实际可以分配给 Python 进程的物理内存.

Ideally, the amount of free RAM should consider only physical memory that can actually be allocated to the Python process.

推荐答案

你试过 SIGAR - System信息收集者和记者?安装后

import os, sigar

sg = sigar.open()
mem = sg.mem()
sg.close() 
print mem.total() / 1024, mem.free() / 1024

希望能帮到你

这篇关于从 Python 中获取总内存/空闲内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆