Skip to content

Commit 6a77806

Browse files
[PR #8636/51d872e backport][3.10] Remove Request.wait_for_disconnection() method (#8650)
Co-authored-by: Sam Bull <[email protected]>
1 parent 1f92213 commit 6a77806

File tree

3 files changed

+11
-30
lines changed

3 files changed

+11
-30
lines changed

CHANGES/8636.breaking.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Removed ``Request.wait_for_disconnection()`` which was mistakenly added briefly in 3.10.0 -- by :user:`Dreamsorcerer`.

aiohttp/web_request.py

+10-17
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
MutableMapping,
2020
Optional,
2121
Pattern,
22-
Set,
2322
Tuple,
2423
Union,
2524
cast,
@@ -50,7 +49,6 @@
5049
reify,
5150
sentinel,
5251
set_exception,
53-
set_result,
5452
)
5553
from .http_parser import RawRequestMessage
5654
from .http_writer import HttpVersion
@@ -146,7 +144,6 @@ class BaseRequest(MutableMapping[str, Any], HeadersMixin):
146144
"_loop",
147145
"_transport_sslcontext",
148146
"_transport_peername",
149-
"_disconnection_waiters",
150147
]
151148
)
152149

@@ -194,7 +191,6 @@ def __init__(
194191
self._task = task
195192
self._client_max_size = client_max_size
196193
self._loop = loop
197-
self._disconnection_waiters: Set[asyncio.Future[None]] = set()
198194

199195
transport = self._protocol.transport
200196
assert transport is not None
@@ -823,21 +819,18 @@ async def _prepare_hook(self, response: StreamResponse) -> None:
823819

824820
def _cancel(self, exc: BaseException) -> None:
825821
set_exception(self._payload, exc)
826-
for fut in self._disconnection_waiters:
827-
set_result(fut, None)
828822

829823
def _finish(self) -> None:
830-
for fut in self._disconnection_waiters:
831-
fut.cancel()
832-
833-
async def wait_for_disconnection(self) -> None:
834-
loop = asyncio.get_event_loop()
835-
fut = loop.create_future() # type: asyncio.Future[None]
836-
self._disconnection_waiters.add(fut)
837-
try:
838-
await fut
839-
finally:
840-
self._disconnection_waiters.remove(fut)
824+
if self._post is None or self.content_type != "multipart/form-data":
825+
return
826+
827+
# NOTE: Release file descriptors for the
828+
# NOTE: `tempfile.Temporaryfile`-created `_io.BufferedRandom`
829+
# NOTE: instances of files sent within multipart request body
830+
# NOTE: via HTTP POST request.
831+
for file_name, file_field_object in self._post.items():
832+
if isinstance(file_field_object, FileField):
833+
file_field_object.file.close()
841834

842835

843836
class Request(BaseRequest):

docs/web_reference.rst

-13
Original file line numberDiff line numberDiff line change
@@ -510,19 +510,6 @@ and :ref:`aiohttp-web-signals` handlers.
510510
required work will be processed by :mod:`aiohttp.web`
511511
internal machinery.
512512

513-
.. method:: wait_for_disconnection()
514-
515-
Returns when the connection that sent this request closes
516-
517-
If there is no client disconnection during request handling, this
518-
coroutine gets cancelled automatically at the end of this request being
519-
handled.
520-
521-
This can be used in handlers as a means of receiving a notification of
522-
premature client disconnection.
523-
524-
.. versionadded:: 3.10
525-
526513
.. class:: Request
527514

528515
A request used for receiving request's information by *web handler*.

0 commit comments

Comments
 (0)