V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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
crytis
V2EX  ›  Python

flask 用 app.run 这种方式启动,有异常特别容易退出,如何解决?

  •  
  •   crytis · Oct 30, 2016 · 9216 views
    This topic created in 3475 days ago, the information mentioned may be changed or developed.

    一有错误、异常进程就直接结束了, try 了也不行。 用别的 server 可以保证不退出吗

    13 replies    2016-11-01 00:47:23 +08:00
    xiamx
        1
    xiamx  
       Oct 30, 2016
    有异常退出不好吗?
    可以用 upstart/systemd 啊
    C0VN
        2
    C0VN  
       Oct 30, 2016
    你说的开发环境吧,看看部署环境是如何使用的 http://docs.jinkan.org/docs/flask/deploying/index.html
    knightdf
        3
    knightdf  
       Oct 30, 2016
    app.run 是用来调试的....线上部署别用这个
    wwqgtxx
        4
    wwqgtxx  
       Oct 30, 2016 via iPhone
    为啥我用过 app.run 之后 sys.exit 都退不出去,貌似没啥 error 比 sys.exit 更 nb 了吧
    sherlocktheplant
        5
    sherlocktheplant  
       Oct 30, 2016
    部署用 uwsgi
    crytis
        6
    crytis  
    OP
       Oct 30, 2016 via iPhone
    @xiamx 关键我 try 了,按我的理解应该 try 住
    @xavierskip 嗯 自己调试的时候
    @wwqgtxx MySQL 连不上就挂了
    wwqgtxx
        7
    wwqgtxx  
       Oct 31, 2016 via iPhone
    @crytis 你有开启 thread=true 么
    bdbai
        8
    bdbai  
       Oct 31, 2016 via Android
    部署用 Gunicorn+Supervisor
    coreki
        9
    coreki  
       Oct 31, 2016 via iPhone
    有异常就退出是为了测试使用 gunicorn 欢迎你
    Eleutherios
        10
    Eleutherios  
       Oct 31, 2016 via iPhone
    @crytis 有 try 没 except 或 Error Type 不对?
    crytis
        11
    crytis  
    OP
       Oct 31, 2016 via iPhone
    @wwqgtxx 没开启,意思是现在是单线程,有异常就挂?
    @bdbai
    @coreki 😂Windows 还没有 gunicorn 说是 20 才支持 Windows?
    @Eleutherios except 的 exception 够大了吧
    wwqgtxx
        12
    wwqgtxx  
       Oct 31, 2016 via iPhone
    @crytis 貌似是的,开启 thread=true 之后,只能用 os._exit 才能退的出去,用 sys.exit 都打不断程序
    cheetah
        13
    cheetah  
       Nov 1, 2016
    开发环境下可以用: https://github.com/mgood/flask-failsafe
    线上部署请用 Gunicorn
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3297 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 51ms · UTC 14:06 · PVG 22:06 · LAX 07:06 · JFK 10:06
    ♥ Do have faith in what you're doing.