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

如何调试一个正在运行的 Python 程序?

  •  
  •   smallpython · 2019-10-29 11:49:57 +08:00 · 4811 次点击
    这是一个创建于 1632 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我想看到变量的值
    16 条回复    2019-11-30 10:33:23 +08:00
    wlsnx
        1
    wlsnx  
       2019-10-29 11:54:11 +08:00   ❤️ 1
    Sylv
        2
    Sylv  
       2019-10-29 11:56:09 +08:00 via iPhone
    问就是 PyCharm。
    wuwukai007
        3
    wuwukai007  
       2019-10-29 11:58:31 +08:00   ❤️ 1
    已经跑以来的程序,没试过,不过要是可以跑之前加个 pysnooper
    pip install pysnooper
    ligyxy
        4
    ligyxy  
       2019-10-29 12:02:14 +08:00   ❤️ 1
    今天的 PyCoder’s Weekly 提到了一个
    https://github.com/julvo/reloading
    ClericPy
        5
    ClericPy  
       2019-10-29 12:02:27 +08:00   ❤️ 1
    google 上随便一搜 python debug running 有好几个吧, 这东西以前在周报只看到过 gdb, 刚随手一搜也有不少啊
    chenqh
        6
    chenqh  
       2019-10-29 12:24:02 +08:00
    print?
    smallpython
        7
    smallpython  
    OP
       2019-10-29 12:29:17 +08:00
    @Sylv pycharm 还能调试正在运行的程序吗
    smallpython
        8
    smallpython  
    OP
       2019-10-29 12:30:49 +08:00
    @ClericPy 我知道,我这不是想看看 v 友有没有什么好用的方法嘛
    ggicci
        9
    ggicci  
       2019-10-29 13:07:26 +08:00
    @wlsnx 卡尔大哥能带飞吗
    Sylv
        10
    Sylv  
       2019-10-29 13:59:00 +08:00
    @smallpython 当然可以,断点调试啥的都可以。
    tiedan
        11
    tiedan  
       2019-10-29 14:01:46 +08:00
    推荐试试神器 pdb
    ruabiubiubiu
        12
    ruabiubiubiu  
       2019-10-29 17:08:05 +08:00
    @ggicci 你就不怕是钢筋卡么
    ggicci
        13
    ggicci  
       2019-10-29 17:28:53 +08:00
    @ruabiubiubiu 不怕,我是万年辅助,只躺不动
    scriptB0y
        14
    scriptB0y  
       2019-10-31 20:23:52 +08:00
    可以用 https://github.com/benfred/py-spy 照一下看看程序在干嘛;

    angwer 在去年分享过调试工具,其中有一部分是可以做到不重启程序的,可以看下: https://github.com/HZPUG/HZPUG.github.io/blob/master/lectures/2018-11-25/%E6%88%91%E7%9A%84Python%E8%BF%9B%E7%A8%8B%E6%80%8E%E4%B9%88%E4%BA%86.pdf
    lowman
        15
    lowman  
       2019-11-30 10:31:24 +08:00
    @smallpython 可以, 打断点, 手动执行下一步, 输出变量值, 本地调试, 远程调试都可以,
    lowman
        16
    lowman  
       2019-11-30 10:33:23 +08:00
    大型的 web 项目, 如果不是需要进行特别复杂的调试, 直接 print 大法就行了..........
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5969 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 02:17 · PVG 10:17 · LAX 19:17 · JFK 22:17
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.