Gunicorn workers timeout no matter what

匆匆过客 提交于 2019-12-04 19:32:47

问题


I'm trying to run a simple flask app through gunicorn, but having my workers timeout no matter what I do. Whether there's activity against the app or not, workers will always timeout after whatever I set the timeout value to. What's causing them to timeout? Requests go through successfully when I make them, but workers still timeout. Here's what I'm running:

gunicorn test_app.py -b 127.0.0.1:8000 --log-level=debug --log-file /tmp/log
 * Running on http://127.0.0.1:5000/
127.0.0.1 - - [28/Aug/2014 11:23:50] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [28/Aug/2014 11:23:53] "GET / HTTP/1.1" 200 -
 * Running on http://127.0.0.1:5000/
 * Running on http://127.0.0.1:5000/

And here's what I'm seeing in /tmp/log:

[2014-08-28 11:23:32 -0700] [36868] [INFO] Listening at: http://127.0.0.1:8000 (36868)
[2014-08-28 11:23:32 -0700] [36868] [INFO] Using worker: sync
[2014-08-28 11:23:32 -0700] [36871] [INFO] Booting worker with pid: 36871
[2014-08-28 11:23:32 -0700] [36868] [DEBUG] 1 workers
[2014-08-28 11:24:02 -0700] [36868] [CRITICAL] WORKER TIMEOUT (pid:36871)
[2014-08-28 11:24:02 -0700] [36868] [DEBUG] 1 workers
[2014-08-28 11:24:03 -0700] [36868] [DEBUG] 1 workers
[2014-08-28 11:24:03 -0700] [36872] [INFO] Booting worker with pid: 36872
[2014-08-28 11:24:03 -0700] [36868] [DEBUG] 1 workers
[2014-08-28 11:24:03 -0700] [36868] [DEBUG] 1 workers
[2014-08-28 11:24:33 -0700] [36868] [CRITICAL] WORKER TIMEOUT (pid:36872)
[2014-08-28 11:24:33 -0700] [36868] [DEBUG] 1 workers
[2014-08-28 11:24:33 -0700] [36872] [INFO] Worker exiting (pid: 36872)
[2014-08-28 11:24:33 -0700] [36873] [INFO] Booting worker with pid: 36873
[2014-08-28 11:24:33 -0700] [36868] [DEBUG] 1 workers
[2014-08-28 11:24:33 -0700] [36868] [DEBUG] 1 workers
[2014-08-28 11:25:03 -0700] [36868] [CRITICAL] WORKER TIMEOUT (pid:36873)

As you can see, my worker times out every 30 seconds, even though there's nothing wrong with it. What gives?


回答1:


For anyone having this issue in the future, the main problem was me doing:

app.run()

and not

if __name__ == '__main__':
    app.run()

with the former, the workers would wind up being run through flask instead of gunicorn, and the whole thing would become confused. Just switching to the latter fixed my issue.




回答2:


Usually worker timeout will happen if the request take more time. Try add new parameter called --timeout <some value> it should work.

ex: gunicorn test_app.py -b 127.0.0.1:8000 --log-level=debug --log-file /tmp/log -t 900



来源:https://stackoverflow.com/questions/25555669/gunicorn-workers-timeout-no-matter-what

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!