aio-libs / aio-libs/aiohttp

Suggesting aiohttp.ClientSession.abort()

Ouverte
#919 4 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
enhancement
Langage dominant
Python
Étoiles
16.5k
Forks
2.4k
Merge moyen
17 h 22 min
PR mergées (30 j)
212

Description

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

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.