温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

python中使用psutil查看内存占用的情况

发布时间:2020-10-05 22:46:11 来源:脚本之家 阅读:200 作者:晓东邪 栏目:开发技术

有的时候需要对python程序内存占用进行监控,这个时候可以用到psutil库,Anaconda中是自带的,如果import出错,可以用pip install psutil(安装在python中)或conda install psutil(安装在Anaconda中)

#常用的:
import psutil
import os
info = psutil.virtual_memory()
print u'内存使用:',psutil.Process(os.getpid()).memory_info().rss
print u'总内存:',info.total
print u'内存占比:',info.percent
print u'cpu个数:',psutil.cpu_count()

其他内置的方法或属性还有:

boot_time
callable
collections
cpu_count
cpu_percent
cpu_stats
cpu_times
cpu_times_percent
disk_io_counters
disk_partitions
disk_usage
errno
functools
long
net_connections
net_if_addrs
net_if_stats
net_io_counters
os
pid_exists
pids
process_iter
pwd
signal
subprocess
swap_memory
sys
test
time
traceback
users
version_info
virtual_memory
wait_procs
win_service_get
win_service_iter

查看windows开机时间

import time
import psutil
print (u'电脑开机时间:{}'.format(time.strftime('%y-%m-%d %H:%M:%S', time.localtime(psutil.boot_time()))))

以上这篇python中使用psutil查看内存占用的情况就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持亿速云。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI