Review a generated async URL fetcher

from asyncio
Python 3.14 advanced 6 min 5 issues to find

Review this generated async URL fetcher against the stated task and identify five distinct risks.

Fetch user-supplied URLs with an async client, preserve input order, allow at most five in-flight requests, apply a two-second deadline to each request, and fail the operation if any request fails.

Python
import asyncio

async def fetch_all(client, urls):
    results = []

    async def fetch_one(url):
        response = await client.get(url)
        results.append(response.text)

    for url in urls:
        asyncio.create_task(fetch_one(url))

    await asyncio.sleep(2)
    return results


async def handler(request, client):
    urls = request.query.getall("url")
    payloads = await fetch_all(client, urls)
    return {"items": payloads}

generated code is illustrative, not from any one model

Open in playground
Report an error