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

crontab 运行 flask 的一个 app 总是执行不成功

  •  
  •   cuixiao603 · 2020-05-12 09:41:32 +08:00 · 2342 次点击
    这是一个创建于 1439 天前的主题,其中的信息可能已经有所发展或是发生改变。

    crontab 运行一个检测脚本就是 app 挂了执行:nohup /usr/bin/python3 /app/app.py > /log/app.log & 执行完成后进程是起来了的,但是访问接口报 500 错误, 查看输出日志之后发现:

     * Serving Flask app "app" (lazy loading)
     * Environment: production
       WARNING: This is a development server. Do not use it in a production deployment.
       Use a production WSGI server instead.
     * Debug mode: off
    

    相比正常执行少了最后那一行

     * Serving Flask app "app" (lazy loading)
     * Environment: production
       WARNING: This is a development server. Do not use it in a production deployment.
       Use a production WSGI server instead.
     * Debug mode: off
     * Running on http://0.0.0.0:5200/ (Press CTRL+C to quit)
    
    

    各位大佬能凭丰富的经验定位出是哪里问题吗

    9 条回复    2020-05-20 12:50:02 +08:00
    Kilerd
        1
    Kilerd  
       2020-05-12 09:49:46 +08:00
    说了多少次,Flask 内置的服务器不能作为生产服务器使用。
    cuixiao603
        2
    cuixiao603  
    OP
       2020-05-12 09:52:21 +08:00
    @Kilerd #1 大佬也不要激动,那我这个问题跟使用 flask 内置服务器有关吗
    Caratpine
        3
    Caratpine  
       2020-05-12 09:54:23 +08:00   ❤️ 1
    开启 debug 模式,然后再用 crontab 运行,看一下报错日志。
    est
        4
    est  
       2020-05-12 10:05:28 +08:00 via Android   ❤️ 1
    因为端口被占了
    frostming
        5
    frostming  
       2020-05-12 10:22:54 +08:00   ❤️ 1
    你把错误输出也重定向一下啊,错误都丢了
    razrlele
        6
    razrlele  
       2020-05-12 10:27:25 +08:00   ❤️ 2
    nohup /usr/bin/python3 /app/app.py &> /log/app.log &

    酱紫就可以把 stderr 也打出来了
    cuixiao603
        7
    cuixiao603  
    OP
       2020-05-12 10:51:28 +08:00
    @frostming #5
    @razrlele #6
    谢谢指点啊,把错误日志输出后发现是代码某一处依然使用相对路径读取文件,改为绝对路径就 ok 了!!
    ashCloud
        8
    ashCloud  
       2020-05-12 11:23:33 +08:00
    开 debug mod 可以看到 error stack
    wingor2015
        9
    wingor2015  
       2020-05-20 12:50:02 +08:00
    supervisior 比 crontab 不知道高到哪里去了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2600 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 04:48 · PVG 12:48 · LAX 21:48 · JFK 00:48
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.