From 51d872e1b87480b84a1a541af394a34b311ec22c Mon Sep 17 00:00:00 2001 From: Sam Bull Date: Thu, 8 Aug 2024 15:56:54 +0100 Subject: [PATCH] Remove Request.wait_for_disconnection() method (#8636) --- CHANGES/8636.breaking.rst | 1 + aiohttp/web_request.py | 24 ++---------------------- docs/web_reference.rst | 14 -------------- 3 files changed, 3 insertions(+), 36 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 1945db3b224..b3a228e4d18 100644 --- a/aiohttp/web_request.py +++ b/aiohttp/web_request.py @@ -19,7 +19,6 @@ MutableMapping, Optional, Pattern, - Set, Tuple, Union, cast, @@ -43,7 +42,6 @@ reify, sentinel, set_exception, - set_result, ) from .http_parser import RawRequestMessage from .http_writer import HttpVersion @@ -141,7 +139,6 @@ class BaseRequest(MutableMapping[str, Any], HeadersMixin): "_loop", "_transport_sslcontext", "_transport_peername", - "_disconnection_waiters", "__weakref__", ) @@ -190,7 +187,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 @@ -817,13 +813,8 @@ 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() - if self._post is None or self.content_type != "multipart/form-data": return @@ -832,19 +823,8 @@ def _finish(self) -> None: # 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 not isinstance(file_field_object, FileField): - continue - - file_field_object.file.close() - - async def wait_for_disconnection(self) -> None: - loop = asyncio.get_event_loop() - fut: asyncio.Future[None] = loop.create_future() - self._disconnection_waiters.add(fut) - try: - await fut - finally: - self._disconnection_waiters.remove(fut) + 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 31898b4c676..a1d48e6d8d1 100644 --- a/docs/web_reference.rst +++ b/docs/web_reference.rst @@ -490,20 +490,6 @@ and :ref:`aiohttp-web-signals` handlers. required work will be processed by :mod:`aiohttp.web` internal machinery. - .. method:: wait_for_disconnection() - :async: - - 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:: 4.0 - .. class:: Request A request used for receiving request's information by *web handler*.