Refs #36315 -- Used contextlib.closing() in ASGIHandler.handle().

This commit is contained in:
Thomas Grainger 2025-11-07 11:13:36 -05:00 committed by Jacob Walls
parent 5ef870fbc5
commit 796cf3d325

View file

@ -3,7 +3,7 @@ import logging
import sys
import tempfile
import traceback
from contextlib import aclosing
from contextlib import aclosing, closing
from asgiref.sync import ThreadSensitiveContext, sync_to_async
@ -174,6 +174,8 @@ class ASGIHandler(base.BaseHandler):
body_file = await self.read_body(receive)
except RequestAborted:
return
with closing(body_file):
# Request is complete and can be served.
set_script_prefix(get_script_prefix(scope))
await signals.request_started.asend(sender=self.__class__, scope=scope)
@ -232,8 +234,6 @@ class ASGIHandler(base.BaseHandler):
else:
await sync_to_async(response.close)()
body_file.close()
async def listen_for_disconnect(self, receive):
"""Listen for disconnect from the client."""
message = await receive()