V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
whx20202
V2EX  ›  Python

Python 程序内存占用越来越大,有没有办法直接查看对象数目,而不修改代码呢?

  •  
  •   whx20202 · 2017-04-12 10:30:54 +08:00 · 4431 次点击
    这是一个创建于 2571 天前的主题,其中的信息可能已经有所发展或是发生改变。

    在网上看了几个内存泄露分析工具,都要 import 什么,或者加一个装饰器

    有没有那种直接在系统里运行,就能检测别的 python 进程内存使用情况的工具?

    12 条回复    2017-04-15 11:06:43 +08:00
    carlonelong
        1
    carlonelong  
       2017-04-12 10:38:31 +08:00
    在系统里运行,你是说一个单独的 binary 文件?
    whx20202
        2
    whx20202  
    OP
       2017-04-12 10:44:10 +08:00
    @carlonelong 也可以是别的 python 文件什么的,暂时没法重启那个 内存泄露的服务,更别说改代码了
    Mirana
        3
    Mirana  
       2017-04-12 11:04:11 +08:00
    trent0806
        4
    trent0806  
       2017-04-12 11:07:33 +08:00
    应该是有吧
    ProjectAmber
        5
    ProjectAmber  
       2017-04-12 11:12:10 +08:00 via iPhone
    https://gist.github.com/simonw/8aa492e59265c1a021f5c5618f9e6b12
    这里提到了一种向运行中的 Python 程序关联 shell 的方法,不确定是否对解决这一问题有帮助。
    janxin
        6
    janxin  
       2017-04-12 11:21:07 +08:00
    systemtap 是一个好方法,但是需要编译 Python 的时候把一些点提前埋进去。我记得 CentOS 默认的 Python 是带的,可以直接用。其他系统 Python 需要自己打 patch 。

    3.6 之后编译加参数就行了。
    VYSE
        7
    VYSE  
       2017-04-12 11:28:01 +08:00
    pyrasite-shell 或 flask 提供一个看 memory 的接口就可以
    gouchaoer
        8
    gouchaoer  
       2017-04-12 11:29:39 +08:00
    检查内存泄漏很麻烦的,命令行程序的话你定时重启就完了
    janxin
        9
    janxin  
       2017-04-12 11:30:45 +08:00
    https://github.com/emfree/systemtap-python-tools 脚本看 scripts/memtrace.stp 就可以了
    ryanzyy
        10
    ryanzyy  
       2017-04-12 16:32:41 +08:00
    看对象的数目是没有用的
    Leak 的对象在 python 里是看不见的
    sagaxu
        11
    sagaxu  
       2017-04-12 17:15:55 +08:00
    这个时候就知道 Java 的好了,哈哈
    Damnever
        12
    Damnever  
       2017-04-15 11:06:43 +08:00
    可以借助 pyrasite
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2752 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 15:23 · PVG 23:23 · LAX 08:23 · JFK 11:23
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.