Ошибка Broken pipe
Есть класс
class AsyncClient:
def __init__(self):
self.__session = None
async def resolve(self):
if self.__session is None:
return
await self.__session.close()
async def request(url):
if self.__session is None:
self.__session = aiohttp.ClientSession()
resp = await self.__session.request(url)
try:
r_ = await resp.json()
except:
r_ = await resp.text()
return r_
В тесте я делаю так:
@pytest.mark.asyncio
async def test_1():
timeout = 3
client = AsyncClient()
_, _ = await client.request('0.0.0.0:8080/test')
time.sleep(timeout)
_, _ = await client.request('0.0.0.0:8080/test')
В таком случае, всё ок. Но мне потребовалось поставить таймату на побольше, так как метод запускает поток. И если я ставлю 10 секунд (на самом деле, 5 достаточно), то получаю следующую ошибку на втором вызове:
../../anaconda3/envs/deps-backend/lib/python3.7/site-packages/aiohttp/client.py:504: in _request
await resp.start(conn)
../../anaconda3/envs/deps-backend/lib/python3.7/site-packages/aiohttp/client_reqrep.py:847: in start
message, payload = await self._protocol.read() # type: ignore # noqa
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <aiohttp.client_proto.ResponseHandler object at 0x7efe394f8750>
async def read(self) -> _T:
if not self._buffer and not self._eof:
assert not self._waiter
self._waiter = self._loop.create_future()
try:
> await self._waiter
E aiohttp.client_exceptions.ClientOSError: [Errno 32] Broken pipe
../../anaconda3/envs/deps-backend/lib/python3.7/site-packages/aiohttp/streams.py:591: ClientOSError