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

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

  •  
  •   JaminT · May 12, 2020 · 3194 views
    This topic created in 2329 days ago, the information mentioned may be changed or developed.

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

    酱紫就可以把 stderr 也打出来了
    JaminT
        7
    JaminT  
    OP
       May 12, 2020
    @frostming #5
    @razrlele #6
    谢谢指点啊,把错误日志输出后发现是代码某一处依然使用相对路径读取文件,改为绝对路径就 ok 了!!
    ashCloud
        8
    ashCloud  
       May 12, 2020
    开 debug mod 可以看到 error stack
    wingor2015
        9
    wingor2015  
       May 20, 2020
    supervisior 比 crontab 不知道高到哪里去了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1077 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 17:24 · PVG 01:24 · LAX 10:24 · JFK 13:24
    ♥ Do have faith in what you're doing.