如何在gunicorn中查看python应用程序的错误

时间:2016-09-02 14:53:52

标签: python error-handling gunicorn falconframework

我有falcon应用程序,用gunicorn运行。如果.py文件中有错误,它会提供回溯,但在grunicorn中它只发送到控制台:

[2016-09-02 17:39:26 +0300] [6927] [INFO] Starting gunicorn 19.6.0
[2016-09-02 17:39:26 +0300] [6927] [INFO] Listening at: http://127.0.0.1:8000 (6927)
[2016-09-02 17:39:26 +0300] [6927] [INFO] Using worker: sync
[2016-09-02 17:39:26 +0300] [6930] [INFO] Booting worker with pid: 6930

唯一的错误输出是:

[2016-09-02 17:39:29 +0300] [6927] [INFO] Shutting down: Master
[2016-09-02 17:39:29 +0300] [6927] [INFO] Reason: Worker failed to boot.

如何获得完整的错误输出?我需要知道导致工人无法启动的原因。

1 个答案:

答案 0 :(得分:1)

这是gunicorn日志(不是猎鹰)的问题。有时它不会输出产生引导失败的异常。所以要调试我的WSGI app我通常做的是使用wsgiref提供的测试服务器运行服务器,如下所示:

from wsgiref import simple_server

if __name__ == '__main__':
    APP_HOST = 8080 #you may want to change this
    APP_HOST = '0.0.0.0' #you may want to change this
    httpd = simple_server.make_server(APP_HOST, APP_PORT, app)
    httpd.serve_forever()

这可以帮助您找出问题所在。