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

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

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

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

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