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
zhoudaiyu
V2EX  ›  Python

如何打印 Python 线程堆栈?

  •  
  •   zhoudaiyu · 2021-04-27 20:32:22 +08:00 via iPhone · 2086 次点击
    这是一个创建于 1087 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    11 条回复    2021-04-28 23:17:26 +08:00
    Kasumi20
        1
    Kasumi20  
       2021-04-27 20:58:53 +08:00
    歪个楼。堆就是堆,栈就是栈,为什么栈要说成堆栈?
    zhoudaiyu
        2
    zhoudaiyu  
    OP
       2021-04-27 21:05:55 +08:00 via iPhone
    @Kasumi20 平时说习惯了,应该是栈
    ch2
        3
    ch2  
       2021-04-27 21:11:00 +08:00
    @Kasumi20 #1 堆栈加在一起就是内存
    786375312123
        4
    786375312123  
       2021-04-27 21:34:16 +08:00
    pycharm 上 debugger 可以直接看 stack trace
    zhoudaiyu
        5
    zhoudaiyu  
    OP
       2021-04-27 21:35:45 +08:00 via iPhone
    @786375312123 额 是跑在服务器上的 websocket 服务 好像不能这么玩
    786375312123
        6
    786375312123  
       2021-04-27 21:41:06 +08:00
    @zhoudaiyu GDB 不也是 debugger 吗?而且我没听说过 gdb 支持 py 的
    Pagliacii
        7
    Pagliacii  
       2021-04-28 09:57:19 +08:00
    ruanimal
        8
    ruanimal  
       2021-04-28 10:30:59 +08:00
    @786375312123 支持的,其实就是 debug python 解释器
    xingheng
        9
    xingheng  
       2021-04-28 22:14:02 +08:00
    RTFM before your asking!
    lcvs
        10
    lcvs  
       2021-04-28 23:04:22 +08:00   ❤️ 2
    可以试试 py-spy,可以对正在运行中的程序进行采样分析
    https://github.com/benfred/py-spy
    zhoudaiyu
        11
    zhoudaiyu  
    OP
       2021-04-28 23:17:26 +08:00 via iPhone
    @lcvs 这个太棒了,感谢感谢
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1401 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 23:49 · PVG 07:49 · LAX 16:49 · JFK 19:49
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.