Skip to content

Add a basic read_with_timeout functionallity #109

@duck-5

Description

@duck-5

The StreamReader read methods don't have a timeout mechanism, and for various reasons they don't won't it as an part of the core library. Here, though, it seems fit to write a wrapper for the basic read method.
Something like:

async def read_with_timeout(reader, n, timeout):
    start_t = time.time()
    data = b''
    while time.time() - start_t < timeout and len(data) < n:
        try:
            data += await asyncio.wait_for(reader.read(1), timeout=timeout):
        except TimeoutError:
            pass
    return data

Would be very helpful.

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