Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pyramid gunicorn and waitress

Tags:

I'm trying to understand the behaviour of Pyramid regarding the [main:server] configuration and gunicorn.

If I use pserve, it'll use the configuration of [main:server], for both waitress and gunicorn. For example:

# development.ini 
[server:main]
use = egg:waitress#main
listen = *:6543

So now, $ pserve development.ini will launch the project with waitress, which is expected. But if I use the command $ gunicorn (with gunicorn or waitress in the ini file) it'll work as well, which is not expected by me.

My questions are:

  • why does this configuration work if I run the command $ gunicorn --paste development.ini?

  • what happens under the hook? is waitress working? (I would say it's not according to the processes in my computer)

like image 744
yami Avatar asked Sep 26 '17 09:09

yami


2 Answers

There are two independent pieces of configuration required to start serving requests for any WSGI app.

1) Which WSGI app to use.

2) Which WSGI server to use.

These pieces are handled separately and can be done in different ways depending on how you set it up. The ini file format is defined by the PasteDeploy library and provides a way for a consumer of the format to determine both the app config and the server config. However, when using gunicorn --paste foo.ini you're already telling gunicorn you want to use the gunicorn server (not waitress) so it ignores the server section and focuses only on loading the app. Gunicorn actually has other ways to load the app as well, but I'll ignore that complexity for now since that part is working for you. Any server config for gunicorn needs to be done separately... it is not reading the [server:main] section when you run gunicorn from the cli. Alternatively you can start your app using pserve which does use the server section to determine what server to use - but in your current setup that would run waitress instead of gunicorn.

like image 94
Michael Merickel Avatar answered Oct 11 '22 13:10

Michael Merickel


So, after lots of reading and test, I have to conclude that:

  • using [main:server] is mandatory for a pyramid application
  • if you are running the application with gunicorn, you have to define this [main:server] nevertheless
  • gunicorn will ignore the use attribute, but pyramid will check the egg exists
  • gunicorn will use the rest of the settings (if any) but they will have less priority than the command line arguments or the config.py file

The reason behind this behaviour is still confusing to me, but at least I can work with it. Any other hints will be very appreciated.

like image 39
yami Avatar answered Oct 11 '22 13:10

yami