I'm trying to use Django 3.0 with Uvicorn and getting this on start:
INFO: Started server process [96219]
INFO: Waiting for application startup.
INFO: ASGI 'lifespan' protocol appears unsupported.
INFO: Application startup complete.
I could turn lifespan off with the --lifespan off flag, but is there a way to have it work with Django? A quick search for Django + lifespan seems to not return anything.
No, lifespan protocol doesn't work with Django 3.0.
See this ticket: https://code.djangoproject.com/ticket/31508
Here's the initial setup I used with django 3.1 / 3.2
EDIT: some rough performance benchmarks: https://github.com/allen-munsch/benchmark-django-fastapi
your_django/old_wsgi.py:
import os
from django.core.wsgi import get_wsgi_application
from dj_static import Cling
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "your_django.settings")
application = Cling(get_wsgi_application())
Previously run as:
newrelic-admin run-program gunicorn your_django.old_wsgi \
-k eventlet --log-file - --timeout 60
your_django/asgi.py:
import os
from django.core.asgi import get_asgi_application
from django.contrib.staticfiles.handlers import ASGIStaticFilesHandler
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pm.settings")
application = ASGIStaticFilesHandler(
get_asgi_application()
)
And to run
gunicorn your_django.asgi --log-level=debug -k uvicorn.workers.UvicornWorker \
--log-file - --timeout 60
# OR for local dev
uvicorn --reload your_django.asgi
related: