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

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

  •  
  •   wolegequ · 2016-09-11 14:32:12 +08:00 · 2824 次点击
    这是一个创建于 2776 天前的主题,其中的信息可能已经有所发展或是发生改变。

    目前做法

    screen -S app

    python app.py

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

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

    请问大家怎么处理的 ?

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

    处理日志,建议使用标准的 logging 模块记录完整 traceback. 可以选择性集成 Sentry 。这样查看错误日志和严重错误告警到邮箱比较方便。除了记录日志,要注意一定要返回合理的值通知上游调用方或者用户。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3290 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 12:12 · PVG 20:12 · LAX 05:12 · JFK 08:12
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.