From f9867e94d5418240c79f6df0876bbae19f55bea4 Mon Sep 17 00:00:00 2001 From: sterliakov Date: Tue, 8 Feb 2022 16:44:34 +0300 Subject: [PATCH] Solve static files deadlock bug for django 3.0+ (#1722) --- channels/staticfiles.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/channels/staticfiles.py b/channels/staticfiles.py index f62597633..8e969ccd6 100644 --- a/channels/staticfiles.py +++ b/channels/staticfiles.py @@ -6,7 +6,10 @@ from django.contrib.staticfiles.views import serve from django.http import Http404 -from .http import AsgiHandler +try: + from django.core.handlers.asgi import ASGIHandler +except ImportError: + from .http import AsgiHandler as ASGIHandler class StaticFilesWrapper: @@ -44,7 +47,7 @@ async def __call__(self, scope, receive, send): return await self.application(scope, receive, send) -class StaticFilesHandler(AsgiHandler): +class StaticFilesHandler(ASGIHandler): """ Subclass of AsgiHandler that serves directly from its get_response. """ @@ -68,7 +71,7 @@ def serve(self, request): """ return serve(request, self.file_path(request.path), insecure=True) - def get_response(self, request): + async def get_response_async(self, request): """ Always tries to serve a static file as you don't even get into this handler subclass without the wrapper directing you here.