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

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

  •  
  •   crytis · 2016-10-30 22:07:00 +08:00 · 8629 次点击
    这是一个创建于 2733 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    13 条回复    2016-11-01 00:47:23 +08:00
    xiamx
        1
    xiamx  
       2016-10-30 22:08:40 +08:00
    有异常退出不好吗?
    可以用 upstart/systemd 啊
    xavierskip
        2
    xavierskip  
       2016-10-30 22:15:58 +08:00
    你说的开发环境吧,看看部署环境是如何使用的 http://docs.jinkan.org/docs/flask/deploying/index.html
    knightdf
        3
    knightdf  
       2016-10-30 22:28:28 +08:00
    app.run 是用来调试的....线上部署别用这个
    wwqgtxx
        4
    wwqgtxx  
       2016-10-30 22:47:38 +08:00 via iPhone
    为啥我用过 app.run 之后 sys.exit 都退不出去,貌似没啥 error 比 sys.exit 更 nb 了吧
    sherlocktheplant
        5
    sherlocktheplant  
       2016-10-30 22:51:27 +08:00
    部署用 uwsgi
    crytis
        6
    crytis  
    OP
       2016-10-30 23:28:39 +08:00 via iPhone
    @xiamx 关键我 try 了,按我的理解应该 try 住
    @xavierskip 嗯 自己调试的时候
    @wwqgtxx MySQL 连不上就挂了
    wwqgtxx
        7
    wwqgtxx  
       2016-10-31 00:02:08 +08:00 via iPhone
    @crytis 你有开启 thread=true 么
    bdbai
        8
    bdbai  
       2016-10-31 00:28:51 +08:00 via Android
    部署用 Gunicorn+Supervisor
    coreki
        9
    coreki  
       2016-10-31 07:43:33 +08:00 via iPhone
    有异常就退出是为了测试使用 gunicorn 欢迎你
    Eleutherios
        10
    Eleutherios  
       2016-10-31 08:07:52 +08:00 via iPhone
    @crytis 有 try 没 except 或 Error Type 不对?
    crytis
        11
    crytis  
    OP
       2016-10-31 12:05:49 +08:00 via iPhone
    @wwqgtxx 没开启,意思是现在是单线程,有异常就挂?
    @bdbai
    @coreki 😂Windows 还没有 gunicorn 说是 20 才支持 Windows?
    @Eleutherios except 的 exception 够大了吧
    wwqgtxx
        12
    wwqgtxx  
       2016-10-31 13:36:38 +08:00 via iPhone
    @crytis 貌似是的,开启 thread=true 之后,只能用 os._exit 才能退的出去,用 sys.exit 都打不断程序
    cheetah
        13
    cheetah  
       2016-11-01 00:47:23 +08:00
    开发环境下可以用: https://github.com/mgood/flask-failsafe
    线上部署请用 Gunicorn
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1005 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 20:08 · PVG 04:08 · LAX 13:08 · JFK 16:08
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.