Optimized MiddlewareMixin coroutine check.

This commit is contained in:
Adam Johnson 2021-12-21 07:41:29 +00:00 committed by GitHub
parent cc752c1c3a
commit 33401cba93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 1 deletions

View File

@ -112,10 +112,12 @@ class MiddlewareMixin:
# Mark the class as async-capable, but do the actual switch
# inside __call__ to avoid swapping out dunder methods
self._is_coroutine = asyncio.coroutines._is_coroutine
else:
self._is_coroutine = None
def __call__(self, request):
# Exit out to async mode, if needed
if asyncio.iscoroutinefunction(self.get_response):
if self._is_coroutine:
return self.__acall__(request)
response = None
if hasattr(self, 'process_request'):