Skip to content
Discussion options

You must be logged in to vote

So, yeah...

Don't try to share an AsyncClient across multiple event loops. That won't work, and I'd assume we probably wouldn't be able to make it work.

You either want...

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

# Not sure why you'd want to do this, but at least it's not broken now...
asyncio.run(home())
asyncio.run(home())
asyncio.run(home())
asyncio.run(home())

Or more sensibly...

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

async def main():
    # Structured correctly.
    # Single client shared across multiple requests.
    async with httpx.Client(…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@lovelydinosaur
Comment options

Answer selected by lovelydinosaur
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #2473 on December 02, 2022 16:21.