[Django]-Running django with ASGI?

0👍

  1. I doesn’t seem that the lifespan feature should be blocking any Django apps that are not using that feature.

  2. If you use sync code in your views, then switching to ASGI doesn’t magically make your view asynchronously. You need async wrappers around it. Check out Django docs about the adapters sync_to_async() and async_to_sync().

  3. I have never seen the usage of django.setup(). I don’t understand your question fully. This is how an asgi.py file should look like:

import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'MyService.settings.local')
application = get_asgi_application()

Still, personally, after setting this all up, my views are still synchronously. I have opened this question about it: Uvicorn async workers are still working synchronously

-1👍

exec envdir .envdir gunicorn ${DJANGO_WSGI_MODULE}:application \
  --name $NAME \
  --timeout 300 \
  --workers $NUM_WORKERS \
  --bind=unix:$SOCKFILE \
  --preload \
  -k uvicorn.workers.UvicornWorker
👤Marin

Leave a comment