aio-libs / aio-libs/aiohttp

Suggesting aiohttp.ClientSession.abort()

Đang mở
#919 4 bình luận 0 reaction 0 người được giao Xem trên GitHub
enhancement
Ngôn ngữ chính
Python
Star
16.5k
Fork
2.4k
Merge trung bình
17 giờ 22 phút
Pull request đã merge (30 ngày)
212

Mô tả

## Long story short

I'm making a web crawler for video contents.
My program checks the content-length field,
and skip downloading if content-length is equal to the local content.
However, resp.close() does not close the connection
when the connection is using HTTPS.

SSLProtocol._start_shutdown() is too graceful so that
the connection is working background to download all the video content.
(chunked encoding is not a solution because some servers do not support them)
This causes my system to have "too many file descriptors in select" error
even though I'm closing connections by "resp.close()".

asyncio.transports.Transport has a nice abstraction "abort()"
which does exactly what I want to do.
However, none of the aiohttp.TCPConnector, aiohttp.ClientSession,
aiohttp.ClientResponse invokes the "abort()".
Considering keep-alive connections, killing connection from a "response" is not clear.
My suggestion is to make "abort()" API to the aiohttp.ClientSession.abort().
(We already have close() in aiohttp.ClientSession and aiohttp.ClientResponse).

Here is my current hack, but I hope that this feature would be possible
without using private field starting with "_".

``` .py
conn = session.connector
if hasattr(conn, "_acquired"):
for transport in itertools.chain(*conn._acquired.values()):
if isinstance(transport, asyncio.transports.Transport):
transport.abort()
```

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.