python中使用psutil查看内存占用的情况
2019/7/15 0:39:30
本文主要是介绍python中使用psutil查看内存占用的情况,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
有的时候需要对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查看内存占用的情况就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持找一找教程网。
这篇关于python中使用psutil查看内存占用的情况的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-08有遇到过吗?同样的规则 Excel 中 比Python 结果大
- 2024-03-30开始python成长之路
- 2024-03-29python optparse
- 2024-03-29python map 函数
- 2024-03-20invalid format specifier python
- 2024-03-18pool.map python
- 2024-03-18threads in python
- 2024-03-14python Ai 应用开发基础训练,字符串,字典,文件
- 2024-03-13id3 algorithm python
- 2024-03-13sum array elements python