Opened 15 months ago

Last modified 5 months ago

#21978 assigned New feature

Add optional gunicorn support to runserver

Reported by: timo Owned by: berkerpeksag
Component: Core (Management commands) Version: master
Severity: Normal Keywords:
Cc: berker.peksag@…, cmawebsite@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

gunicorn has added a --reload option for code reloading which should lower the barrier of entry to removing our own HTTP server functionality.

Simply deprecating and removing the runserver management command entirely may not be desirable. As Loic noted on IRC "even if we use gunicorn, we still need some special handling for the dev server, we run validate() and now there are some migrations checks going as well. So would we really deprecate runserver? rather than just change the underlying webserver it wraps?"

Michael Manfre also expressed concern the gunicorn does not currently work on Windows.

Aymeric suggested: "optional support for gunicorn could be an interesting start."

Change History (7)

comment:1 Changed 11 months ago by berkerpeksag

  • Cc berker.peksag@… added
  • Owner changed from nobody to berkerpeksag
  • Status changed from new to assigned

I have a WIP patch for this ticket. Before open a pull request, I'd like to discuss structure of the runserver command.

Current choices:

  1. Add a new "--gunicorn" option to runserver: ./manage.py runserver --gunicorn -c gunicorn_conf.py

If the -c option is not given, use existing runserver options e.g.:

./manage.py runserver --gunicorn [--noreload] [optional port number, or ipaddr:port]

  1. Add a new "rungunicorn" command.

Options:

Use cases:

  • Use default options: ./manage.py rungunicorn (same as ./manage.py runserver)
  • Read config information from a file: ./manage.py rungunicorn -c conf.py (this is the configuration file used by Gunicorn)

Thoughts?

Thanks!

comment:2 Changed 11 months ago by timo

I envisioned a more transparent integration. I was thinking that if gunicorn is installed, then runserver would use that automatically (passing data to --reload and --bind from the current runserver options). You can always use the full gunicorn integration if you need the other options. Do you think that approach would be too limiting from a user perspective?

comment:3 Changed 11 months ago by berkerpeksag

I was thinking that if gunicorn is installed, then runserver would use that automatically (passing data to --reload and --bind from the current runserver options).

Ah, that is a good idea. Also, we can pass the settings.DEBUG setting to Gunicorn's configration.

Do you think that approach would be too limiting from a user perspective?

No. I think that approach is a good start. It's a development server afterall.

BTW, my WIP patch is at https://github.com/berkerpeksag/django/compare/ticket-21978_gunicorn I will update it later.

Thanks!

comment:4 Changed 6 months ago by collinanderson

  • Cc cmawebsite@… added

comment:5 Changed 6 months ago by berkerpeksag

I'll update my branch to address comment:2 and open a PR in a day or two.

comment:6 Changed 6 months ago by berkerpeksag

  • Has patch set

https://github.com/django/django/pull/3461

I hardcoded the port number in the test, but I couldn't find any helper in the Django test suite to find an unused port number. Is there a helper like https://hg.python.org/cpython/file/default/Lib/test/support/__init__.py#l578

Also, should I add an --disable-gunicorn option to runserver? Currently, there is no way to disable gunicorn in runserver.

comment:7 Changed 5 months ago by timgraham

  • Patch needs improvement set

LiveServerTestCase has some logic to find an unused port.

I don't see a need for an option to disable it (if you don't have gunicorn installed, it's disabled anyway, right?)

By the way, it seems that Windows support is not too far off for gunicorn so let's wait to merge this until that's done. Then we can see if this is comprehensive enough to deprecate the non-gunicorn version.

Note: See TracTickets for help on using tickets.
Back to Top