推荐学习书目
› 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 · Apr 12, 2017 · 5552 views
    This topic created in 3500 days ago, the information mentioned may be changed or developed.

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

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

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

    3.6 之后编译加参数就行了。
    VYSE
    VYSE
    Apr 12, 2017
    7
    pyrasite-shell 或 flask 提供一个看 memory 的接口就可以
    gouchaoer
    gouchaoer
    Apr 12, 2017
    8
    检查内存泄漏很麻烦的,命令行程序的话你定时重启就完了
    janxin
    janxin
    Apr 12, 2017
    9
    https://github.com/emfree/systemtap-python-tools 脚本看 scripts/memtrace.stp 就可以了
    ryanzyy
    ryanzyy
    Apr 12, 2017
    10
    看对象的数目是没有用的
    Leak 的对象在 python 里是看不见的
    sagaxu
    sagaxu
    Apr 12, 2017
    11
    这个时候就知道 Java 的好了,哈哈
    Damnever
    Damnever
    Apr 15, 2017
    12
    可以借助 pyrasite
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1316 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 52ms · UTC 23:56 · PVG 07:56 · LAX 15:56 · JFK 18:56
    ♥ Do have faith in what you're doing.