Skip to content

What is the right way to recv responses? #807

@altonotch

Description

@altonotch

There is something I don't understand about how to get a response messages, probably due to lack of understanding how asycio works.

Currently I have following code:

async def send_message(conn, message):
    await conn.send(payload)
    return await conn.recv()

This works fine for one call, but fails for multiple concurrent calls with error:

cannot call recv while another coroutine is already waiting for the next message

I tried using asyncio.wait_for and asyncio.ensure_future but it all fails with same error. One request succeeds the rest fail.

What would be the best way to send a message and receive a response?
Any help would be highly appreciated 🙏

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