aio-libs / aio-libs/aiohttp

Suggesting aiohttp.ClientSession.abort()

Offen
#919 4 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
enhancement
Vorherrschende Sprache
Python
Sterne
16.5k
Forks
2.4k
Ø Merge
17 Std. 22 Min.
Gemergte PRs (30 T.)
212

Beschreibung

## 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()
```

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.