[Django] #34109: Uvicorn can be run without installing gunicorn

2 views
Skip to first unread message

Django

unread,
Oct 20, 2022, 12:38:49 PM10/20/22
to django-...@googlegroups.com
#34109: Uvicorn can be run without installing gunicorn
------------------------------------------+------------------------
Reporter: Simon Willison | Owner: nobody
Type: Uncategorized | Status: new
Component: Documentation | Version: 4.1
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------+------------------------
https://docs.djangoproject.com/en/4.1/howto/deployment/asgi/uvicorn/
currently says you should do this:

python -m pip install uvicorn gunicorn

Then:

gunicorn myproject.asgi:application -k uvicorn.workers.UvicornWorker

This isn't actually necessary: you can install just `uvicorn` and then do
this:

uvicorn myproject.asgi:application

--
Ticket URL: <https://code.djangoproject.com/ticket/34109>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Oct 20, 2022, 12:59:33 PM10/20/22
to django-...@googlegroups.com
#34109: Uvicorn can be run without installing gunicorn
--------------------------------+--------------------------------------

Reporter: Simon Willison | Owner: nobody
Type: Uncategorized | Status: new
Component: Documentation | Version: 4.1
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------------------------
Changes (by Mariusz Felisiak):

* cc: Thomas Grainger, Carlton Gibson (added)


Comment:

This was added in c1442e1192057a3bf14aecbaa1b713eee139eaff, see
[https://github.com/django/django/pull/13455 PR].

--
Ticket URL: <https://code.djangoproject.com/ticket/34109#comment:1>

Django

unread,
Oct 20, 2022, 1:24:11 PM10/20/22
to django-...@googlegroups.com
#34109: Uvicorn can be run without installing gunicorn
--------------------------------+--------------------------------------
Reporter: Simon Willison | Owner: nobody
Type: Uncategorized | Status: new
Component: Documentation | Version: 4.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------------------------

Comment (by Simon Willison):

Huh, that's surprising. I've been deploying Uvicorn apps for a few years
now without using gunicorn at all.

https://github.com/django/django/pull/13455 seems to have made that
decision based on the Uvicorn docs themselves at
https://www.uvicorn.org/deployment/#gunicorn - which do recommend gunicorn
for production, but don't explain why.

I'm going to try and work out WHY they recommend gunicorn, and maybe
suggest a change to the Django docs that helps make that clear.

--
Ticket URL: <https://code.djangoproject.com/ticket/34109#comment:2>

Django

unread,
Oct 20, 2022, 1:28:13 PM10/20/22
to django-...@googlegroups.com
#34109: Uvicorn can be run without installing gunicorn
--------------------------------+--------------------------------------
Reporter: Simon Willison | Owner: nobody
Type: Uncategorized | Status: new
Component: Documentation | Version: 4.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------------------------

Comment (by Simon Willison):

It looks like the recommendation to use gunicorn with uvicorn dates back
to this commit four years ago:
https://github.com/encode/uvicorn/commit/07c6c18945ab4f4167118e717e197adce3aee3da
#diff-
b4d68dc855d0f9476d3f2ee343853bd21bf82ea9960d0cf06661baa244439dd6R93-R111 -
and prior to that fix gunicorn was baked into uvicorn itself.

--
Ticket URL: <https://code.djangoproject.com/ticket/34109#comment:3>

Django

unread,
Oct 20, 2022, 1:31:23 PM10/20/22
to django-...@googlegroups.com
#34109: Uvicorn can be run without installing gunicorn
--------------------------------+--------------------------------------
Reporter: Simon Willison | Owner: nobody
Type: Uncategorized | Status: new
Component: Documentation | Version: 4.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------------------------

Comment (by Simon Willison):

Best answer I've found so far is this comment by Tom Christie:
https://github.com/encode/uvicorn/issues/303#issuecomment-464154975

So: Gunicorn will give you multiple worker processes, as well as
monitoring and restarting any crashed processes. We might start to have
some of those things built directly into Uvicorn at some point, but for
now if you want multiple processes you need to use Gunicorn or some other
process manager such as circus.

--
Ticket URL: <https://code.djangoproject.com/ticket/34109#comment:4>

Django

unread,
Oct 20, 2022, 1:33:23 PM10/20/22
to django-...@googlegroups.com
#34109: Uvicorn can be run without installing gunicorn
--------------------------------+--------------------------------------
Reporter: Simon Willison | Owner: nobody
Type: Uncategorized | Status: new
Component: Documentation | Version: 4.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------------------------

Comment (by Simon Willison):

The FastAPI deployment documentation talks about reasons to use Gunicorn
here: https://fastapi.tiangolo.com/deployment/server-workers/

--
Ticket URL: <https://code.djangoproject.com/ticket/34109#comment:5>

Django

unread,
Oct 20, 2022, 1:38:54 PM10/20/22
to django-...@googlegroups.com
#34109: Uvicorn can be run without installing gunicorn
--------------------------------+--------------------------------------
Reporter: Simon Willison | Owner: nobody
Type: Uncategorized | Status: new
Component: Documentation | Version: 4.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------------------------

Comment (by Simon Willison):

There's an interesting draft PR against Uvicorn here which updates their
deployment documentation to reflect current recommendations.

https://github.com/encode/uvicorn/pull/1607/files

One of the new points in there is the idea that gunicorn isn't necessary
if you are deploying inside a container - where using uvicorn alone works
fine.

But... that PR is still being discussed. I don't think the advice there is
stable and agreed upon yet.

--
Ticket URL: <https://code.djangoproject.com/ticket/34109#comment:6>

Django

unread,
Oct 20, 2022, 1:40:42 PM10/20/22
to django-...@googlegroups.com
#34109: Uvicorn can be run without installing gunicorn
--------------------------------+--------------------------------------
Reporter: Simon Willison | Owner: nobody
Type: Uncategorized | Status: new
Component: Documentation | Version: 4.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------------------------

Comment (by Simon Willison):

The title of the page at
https://docs.djangoproject.com/en/4.1/howto/deployment/asgi/uvicorn/ is
"How to use Django with Uvicorn".

As such, I think it's worth explaining both the with-gunicorn and without-
gunicorn mechanisms. I'll update my PR to do that instead.

--
Ticket URL: <https://code.djangoproject.com/ticket/34109#comment:7>

Django

unread,
Oct 20, 2022, 1:48:37 PM10/20/22
to django-...@googlegroups.com
#34109: Uvicorn can be run without installing gunicorn
--------------------------------+--------------------------------------
Reporter: Simon Willison | Owner: nobody
Type: Uncategorized | Status: new
Component: Documentation | Version: 4.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------------------------

Comment (by Simon Willison):

Updated my PR to add the Gunicorn content back in as a separate section:
https://github.com/django/django/pull/16199/commits/ab2b704f652ecde718cf32d4b1e441a4087e92f1

--
Ticket URL: <https://code.djangoproject.com/ticket/34109#comment:8>

Django

unread,
Oct 20, 2022, 2:17:13 PM10/20/22
to django-...@googlegroups.com
#34109: Uvicorn can be run without installing gunicorn
--------------------------------+--------------------------------------
Reporter: Simon Willison | Owner: nobody
Type: Uncategorized | Status: new
Component: Documentation | Version: 4.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------------------------

Comment (by Simon Willison):

Just talked to Andrew Godwin about this. He confirmed that Gunicorn isn't
necessary when running applications in a container environment which
features a separate layer that handles automatic restarts on failure, such
as Kubernetes.

--
Ticket URL: <https://code.djangoproject.com/ticket/34109#comment:9>

Django

unread,
Oct 26, 2022, 5:51:49 AM10/26/22
to django-...@googlegroups.com
#34109: Uvicorn can be run without installing gunicorn
-------------------------------------+-------------------------------------
Reporter: Simon Willison | Owner: Simon
Type: | Willison
Cleanup/optimization | Status: assigned

Component: Documentation | Version: 4.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* owner: nobody => Simon Willison
* status: new => assigned
* has_patch: 0 => 1
* type: Uncategorized => Cleanup/optimization
* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/34109#comment:10>

Django

unread,
Oct 26, 2022, 5:52:18 AM10/26/22
to django-...@googlegroups.com
#34109: Uvicorn can be run without installing gunicorn
-------------------------------------+-------------------------------------
Reporter: Simon Willison | Owner: Simon
Type: | Willison
Cleanup/optimization | Status: closed
Component: Documentation | Version: 4.1
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by GitHub <noreply@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"022a864a5d1de28b853f009566a24be251e90d96" 022a864a]:
{{{
#!CommitTicketReference repository=""
revision="022a864a5d1de28b853f009566a24be251e90d96"
Fixed #34109 -- Updated instructions for running with Uvicorn.

Co-authored-by: Paolo Melchiorre <pa...@melchiorre.org>
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/34109#comment:11>

Django

unread,
Oct 26, 2022, 5:55:21 AM10/26/22
to django-...@googlegroups.com
#34109: Uvicorn can be run without installing gunicorn
-------------------------------------+-------------------------------------
Reporter: Simon Willison | Owner: Simon
Type: | Willison
Cleanup/optimization | Status: closed
Component: Documentation | Version: 4.1
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Carlton Gibson <carlton.gibson@…>):

In [changeset:"ccb830e21a11d9aa53b5360c682d8be994f45eea" ccb830e2]:
{{{
#!CommitTicketReference repository=""
revision="ccb830e21a11d9aa53b5360c682d8be994f45eea"
[4.1.x] Fixed #34109 -- Updated instructions for running with Uvicorn.

Co-authored-by: Paolo Melchiorre <pa...@melchiorre.org>
Backport of 022a864a5d1de28b853f009566a24be251e90d96 from main
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/34109#comment:12>

Reply all
Reply to author
Forward
0 new messages