17

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?

2 Answers 2

12

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.

4
7

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.