Skip to content

Why using synchronous get in flags_asyncio.py #40

Open
@ngokchaoho

Description

@ngokchaoho

When downloading the flags in

async def get_flag(client: AsyncClient, cc: str) -> bytes:  4
    url = f'{BASE_URL}/{cc}/{cc}.gif'.lower()
    resp = await client.get(url, timeout=6.1,
                                  follow_redirects=True)  5
    return resp.read()  6

it seems that we read the response using .read() which is synchronous, why don't we

return await resp.aread()

instead?

The explanation seems to be for client.get() where it is doing network IO asynchrnously provided by httpx. But not for read()

6

    Network I/O operations are implemented as coroutine methods, so they are driven asynchronously by the asyncio event loop.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions