mock_sobes
← aiohttp — async HTTP client/server, ClientSession, connector pool
senior correct_vs_wrong #452
Какой клиент правильнее для production? ```python # Вариант A async with aiohttp.ClientSession() as s: async with s.get(url, timeout=5) as r: return await r.json() # Вариант B timeout = aiohttp.ClientTimeout(total=30, connect=5, sock_read=10) async with aiohttp.ClientSession(timeout=timeout) as s: for attempt in range(3): try: async with s.get(url) as r: r.raise_for_status() return await r.json() except (aiohttp.ClientError, asyncio.TimeoutError) as e: if attempt == 2: raise await asyncio.sleep(2 ** attempt + random.random()) ```
Чтобы решить вопрос и сохранить попытку — войди.