5

when I run the app using:

gunicorn --log-level debug --workers 3 myapp.asgi:application --worker-class uvicorn.workers.UvicornWorker

I see the warning

ASGI 'lifespan' protocol appears unsupported.
  1. after reading here I understand that django do not support, but is this have any effect on my app? or where should the effect be?
  2. My app is using sync endpoints, for example:
class MyViewSet(viewsets.ModelViewSet):
    queryset = My.objects.all()
    serializer_class = MySerializer

is by running using ASGI the call to the database would be async?

  • I don't use any web sockets
  1. I can see online many version for the asgi.py file, with manny different middleware and the django.setup() keyword, where can I find a documentation about the use cases?
1
  • Better one question at one post... Lifespan is just a event so, like if the application start up, it will know, restart, then it will know only. Commented Mar 24, 2022 at 9:16

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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

2 Comments

How does it answer the questions? Can you maybe elaborate?
It helps more if you supply an explanation why this is the preferred solution and explain how it works. We want to educate, not just provide code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.