Skip to content

Completing Requests After AsyncClient.aclose() #2093

Answered by tomchristie
aaronst asked this question in Q&A
Discussion options

You must be logged in to vote

If you close a client while it still has requests/responses in flight, it'll raise a RuntimeError indicating that you've closed the client incorrectly.

To properly perform an early close you'd need to cancel any not-yet-complete tasks before closing the client.

You shouldn't run into this as an issue unless you've got a bit of an oddly structured (broken) code.


A bit of additional context here in case you're interested...

Python's asyncio doesn't (yet) protect developers much here because of the way it allows tasks to be created, and then forgotten about.

TaskGroups are coming to Python with 3.11, which will be a much improved API for managing task concurrency.

In the meantime anyio is a…

Replies: 4 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@aaronst
Comment options

@tomchristie
Comment options

Answer selected by tomchristie
Comment options

You must be logged in to vote
0 replies
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
Category
Q&A
Labels
None yet
3 participants