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

小白问题,求教 Exception 的正确处理姿势

  •  
  •   wolegequ · Sep 11, 2016 · 3913 views
    This topic created in 3669 days ago, the information mentioned may be changed or developed.

    目前做法

    screen -S app

    python app.py

    其实并没有使用日志,只是使用了 try except,在 except 里 print Exception.

    如果程序报错,就切换到 screen 查看.

    请问大家怎么处理的 ?

    7 replies  •  2016-09-12 08:50:59 +08:00
    techmoe
        1
    techmoe  
       Sep 11, 2016 via Android
    我也想知道,因为我这块也不熟
    但基本来讲感觉都是记录下日志然后退掉吧
    mrytsr
        2
    mrytsr  
       Sep 11, 2016 via Android
    supervisor
    wolegequ
        3
    wolegequ  
    OP
       Sep 11, 2016
    @mrytsr r u sure ? = = !
    DuckJK
        4
    DuckJK  
       Sep 11, 2016
    这是某个镜像么。。。
    wolegequ
        6
    wolegequ  
    OP
       Sep 11, 2016
    @DuckJK 镜像 ?
    sylecn
        7
    sylecn  
       Sep 12, 2016   ❤️ 1
    运行 python 最好使用 OS 自带的 init 工具,比如 upstart 或者 systemd 。
    如果实在不想用这些, supervisord 或者 runit 这类的也可以。但是不要用 screen/tmux 。

    处理日志,建议使用标准的 logging 模块记录完整 traceback. 可以选择性集成 Sentry 。这样查看错误日志和严重错误告警到邮箱比较方便。除了记录日志,要注意一定要返回合理的值通知上游调用方或者用户。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   5033 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 07:25 · PVG 15:25 · LAX 00:25 · JFK 03:25
    ♥ Do have faith in what you're doing.