3

my app was running great but then I changed some things and now it can sometimes 'think' for more then 30 seconds before getting back to me. The problem is that Gunicorn times-out after 30 seconds:

[2016-03-28 18:25:52 +0000] [3] [CRITICAL] WORKER TIMEOUT (pid:8)
2016-03-28T18:25:52.625220+00:00 app[web.1]:
[2016-03-28 18:25:52 +0000] [8] [INFO] Worker exiting (pid: 8)

Now, I did some research and I know that I need to create a config file for Gunicorn and put a command to override Gunicorn's timeout default, like this: TIMEOUT=120 But how do I do that? I mean, how do I tell Gunicorn to look in, for example, gunicorn_config.txt and respect the laws I create for it there?

Kristifer Szabo
  • 519
  • 3
  • 7
  • 16

1 Answers1

6

Config files can be written as an INI file or as a Python file. If you're using a Python file (which is what I'd recommend), put this inside it:

timeout = 120

Or, if you want to use an INI file:

[server:main]
timeout = 120

Then, when you run Gunicorn, add a -c option to tell Gunicorn where your config file is, like this:

gunicorn -c config.py ...

See this file for a list of options that you can use in your config file.


For your example, you don't need a config file at all. Simply run Gunicorn with the --timeout option:

gunicorn --timeout 120 ...
Aaron Christiansen
  • 11,584
  • 5
  • 52
  • 78
  • Awesome answer. I tried the simple solution `gunicorn --timeout 120` but it threw me this error `ImportError: No module named 'fcntl'` which, after some research, I discovered is because Gunicorn doesn't run on windows..? Do you know anything about that? Is their a way around it? – Kristifer Szabo Mar 28 '16 at 19:02
  • @KristiferSzabo `fcntl` is a tool which is able to set file flags; it's Linux only which is why you get an `ImportError`. It [doesn't look like it's easy](http://stackoverflow.com/questions/1422368/fcntl-substitute-on-windows) to get around that, and most people seem to recommend using a Linux VM instead. – Aaron Christiansen Mar 28 '16 at 19:06
  • @KristiferSzabo Full Windows support appears to be planned, and with comments on [this GitHub issue from 3 days ago](https://github.com/benoitc/gunicorn/issues/524) it looks like a Windows version may be in development. – Aaron Christiansen Mar 28 '16 at 19:08
  • Thanks for clarifying. There was only a few cases in which the app would trigger the timeout, ill just avoid those cases from now on. Thanks again – Kristifer Szabo Mar 28 '16 at 19:09
  • @AaronChristiansen I am using Python to build a line-bot right now on windows. I tried to put [server:main] timeout = 120 in ini file which store token and secret but still not working. Would you like to give me some advice? Thanks! – Makiyo Dec 12 '17 at 06:05
  • 2
    Changed in version 19.4: Loading the config from a Python module requires the `python:` prefix. https://docs.gunicorn.org/en/stable/settings.html#settings – trallnag Mar 24 '20 at 20:21