From 6a778061eb3d66146012ceef760c8d84b7be6cf3 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 8 Aug 2024 10:46:18 -0500 Subject: [PATCH] [PR #8636/51d872e backport][3.10] Remove Request.wait_for_disconnection() method (#8650) Co-authored-by: Sam Bull --- CHANGES/8636.breaking.rst | 1 + aiohttp/web_request.py | 27 ++++++++++----------------- docs/web_reference.rst | 13 ------------- 3 files changed, 11 insertions(+), 30 deletions(-) create mode 100644 CHANGES/8636.breaking.rst diff --git a/CHANGES/8636.breaking.rst b/CHANGES/8636.breaking.rst new file mode 100644 index 00000000000..ae3d599bf7a --- /dev/null +++ b/CHANGES/8636.breaking.rst @@ -0,0 +1 @@ +Removed ``Request.wait_for_disconnection()`` which was mistakenly added briefly in 3.10.0 -- by :user:`Dreamsorcerer`. diff --git a/aiohttp/web_request.py b/aiohttp/web_request.py index 28d9ef3d10b..a485f0dcea6 100644 --- a/aiohttp/web_request.py +++ b/aiohttp/web_request.py @@ -19,7 +19,6 @@ MutableMapping, Optional, Pattern, - Set, Tuple, Union, cast, @@ -50,7 +49,6 @@ reify, sentinel, set_exception, - set_result, ) from .http_parser import RawRequestMessage from .http_writer import HttpVersion @@ -146,7 +144,6 @@ class BaseRequest(MutableMapping[str, Any], HeadersMixin): "_loop", "_transport_sslcontext", "_transport_peername", - "_disconnection_waiters", ] ) @@ -194,7 +191,6 @@ def __init__( self._task = task self._client_max_size = client_max_size self._loop = loop - self._disconnection_waiters: Set[asyncio.Future[None]] = set() transport = self._protocol.transport assert transport is not None @@ -823,21 +819,18 @@ async def _prepare_hook(self, response: StreamResponse) -> None: def _cancel(self, exc: BaseException) -> None: set_exception(self._payload, exc) - for fut in self._disconnection_waiters: - set_result(fut, None) def _finish(self) -> None: - for fut in self._disconnection_waiters: - fut.cancel() - - async def wait_for_disconnection(self) -> None: - loop = asyncio.get_event_loop() - fut = loop.create_future() # type: asyncio.Future[None] - self._disconnection_waiters.add(fut) - try: - await fut - finally: - self._disconnection_waiters.remove(fut) + if self._post is None or self.content_type != "multipart/form-data": + return + + # NOTE: Release file descriptors for the + # NOTE: `tempfile.Temporaryfile`-created `_io.BufferedRandom` + # NOTE: instances of files sent within multipart request body + # NOTE: via HTTP POST request. + for file_name, file_field_object in self._post.items(): + if isinstance(file_field_object, FileField): + file_field_object.file.close() class Request(BaseRequest): diff --git a/docs/web_reference.rst b/docs/web_reference.rst index ddd5a3c264c..bb22cfd6369 100644 --- a/docs/web_reference.rst +++ b/docs/web_reference.rst @@ -510,19 +510,6 @@ and :ref:`aiohttp-web-signals` handlers. required work will be processed by :mod:`aiohttp.web` internal machinery. - .. method:: wait_for_disconnection() - - Returns when the connection that sent this request closes - - If there is no client disconnection during request handling, this - coroutine gets cancelled automatically at the end of this request being - handled. - - This can be used in handlers as a means of receiving a notification of - premature client disconnection. - - .. versionadded:: 3.10 - .. class:: Request A request used for receiving request's information by *web handler*.