Suggesting aiohttp.ClientSession.abort()
- Lenguaje dominante
- Python
- Estrellas
- 16.5k
- Forks
- 2.4k
- Merge medio
- 17 h 22 min
- PR fusionados (30 d)
- 212
Descripción
## 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()
```
Guía de contribución
Evaluación
Este issue todavía no se ha evaluado.