Skip to content
Discussion options

You must be logged in to vote

I'm not able to replicate that...

import asyncio

import httpx


async def request(url):
    async with httpx.AsyncClient() as client:
        try:
            await client.get(url)
        except BaseException as exc:
            print('Request exception', type(exc), exc)
            raise


async def main():
    url = 'https://httpbin.org/delay/3'  # Some unreachable resource with delay
    task = asyncio.create_task(request(url))
    await asyncio.sleep(1)
    task.cancel()
    try:
        await task
    except BaseException as exc:
        print('Task exception', type(exc), exc)


asyncio.run(main())

Results in...

$ python ./example.py 
Request exception <class 'asyncio.exceptions.Ca…

Replies: 4 comments 5 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by lovelydinosaur
Comment options

You must be logged in to vote
5 replies
@lovelydinosaur
Comment options

@decaz
Comment options

@decaz
Comment options

@lovelydinosaur
Comment options

@decaz
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants