栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Linux+python内存释放

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Linux+python内存释放

--si use powers of 1000 not 1024 -l, --lohi show detailed low and high memory statistics -t, --total show total for RAM swap -s N, --seconds N repeat printing every N seconds -c N, --count N repeat printing N times, then exit -w, --wide wide output --help display this help and exit -V, --version output version information and exit

例如

username:~$ free -h
 total used free shared buff/cache available
Mem: 15Gi 3.8Gi 9.0Gi 100Mi 2.7Gi 11Gi
Swap: 2.0Gi 924Mi 1.1Gi
运行程序时可以使用top命令查看实时情况 username:~$ top 释放空间 在终端中输入 一般直接使用第三行
sudo sh -c echo 1 /proc/sys/vm/drop_caches 
sudo sh -c echo 2 /proc/sys/vm/drop_caches 
sudo sh -c echo 3 /proc/sys/vm/drop_caches 

1表示清空 pagecache
2表示清空 dentries 和 inodes
3表示清空所有缓存 pagecache、dentries 和 inodes

python中运行程序时避免过多内存占用时可以1.del删除变量 2.调用标准库中gc模块
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import gc
del a 
gc.collect()
jupyter notebook中打开一个 .ipynb 再关闭时不会立刻释放kernel 需要手动关闭(点shutdown)。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/267052.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号