Skip to content

Call async request several times with the same AsyncClient with asyncio.run() is causing RuntimeError: Event loop is closed #2473

@PFaurel

Description

@PFaurel

When AsyncClient is used several times with an async function that's sending an http request, the first time is successful, all other attempts are failing with RuntimeError exception and "Event loop is closed" error message.

To reproduce:

import httpx

if name == 'main':

client = httpx.AsyncClient()

async def home():
    r = await client.get('https://www.example.com/')
    return r

asyncio.run(home())
asyncio.run(home())  # => RuntimeError: Event loop is closed
asyncio.run(home())  # => RuntimeError: Event loop is closed
asyncio.run(home())  # => RuntimeError: Event loop is closed

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