推荐学习书目
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
zhoudaiyu
V2EX  ›  Python

如何打印 Python 线程堆栈?

  •  
  •   zhoudaiyu ·
    PRO
    · Apr 27, 2021 via iPhone · 2912 views
    This topic created in 1868 days ago, the information mentioned may be changed or developed.

    现在线程占用 CPU 比较多,但是代码用的开源的,还没有理清逻辑,想直接在线 debug 一下线程。用什么工具好? GDB 、pyflame,还是其他什么工具?

    11 replies    2021-04-28 23:17:26 +08:00
    Kasumi20
        1
    Kasumi20  
       Apr 27, 2021
    歪个楼。堆就是堆,栈就是栈,为什么栈要说成堆栈?
    zhoudaiyu
        2
    zhoudaiyu  
    OP
    PRO
       Apr 27, 2021 via iPhone
    @Kasumi20 平时说习惯了,应该是栈
    ch2
        3
    ch2  
       Apr 27, 2021
    @Kasumi20 #1 堆栈加在一起就是内存
    786375312123
        4
    786375312123  
       Apr 27, 2021
    pycharm 上 debugger 可以直接看 stack trace
    zhoudaiyu
        5
    zhoudaiyu  
    OP
    PRO
       Apr 27, 2021 via iPhone
    @786375312123 额 是跑在服务器上的 websocket 服务 好像不能这么玩
    786375312123
        6
    786375312123  
       Apr 27, 2021
    @zhoudaiyu GDB 不也是 debugger 吗?而且我没听说过 gdb 支持 py 的
    ruanimal
        8
    ruanimal  
       Apr 28, 2021
    @786375312123 支持的,其实就是 debug python 解释器
    xingheng
        9
    xingheng  
       Apr 28, 2021
    RTFM before your asking!
    lcvs
        10
    lcvs  
       Apr 28, 2021   ❤️ 2
    可以试试 py-spy,可以对正在运行中的程序进行采样分析
    https://github.com/benfred/py-spy
    zhoudaiyu
        11
    zhoudaiyu  
    OP
    PRO
       Apr 28, 2021 via iPhone
    @lcvs 这个太棒了,感谢感谢
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1360 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 17:10 · PVG 01:10 · LAX 10:10 · JFK 13:10
    ♥ Do have faith in what you're doing.