Replies: 2 comments
-
|
I'm going to start this off as a discussion rather than an issue. Okay, could you help me out by providing a minimal reproducible example? Bits of this that I think we'd need to understand more clearly...
|
Beta Was this translation helpful? Give feedback.
0 replies
-
|
I got a similar issue raise a proper exception except |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, I am using httpx to make asynchronous requests in a generator function. However, I encountered a problem when I tried to cancel the generator using
generator.close()orasyncio.gather(*tasks, return_exceptions=True). The generator did not exit gracefully and raised anasyncio.CancelledErrorinstead of a return. This caused some unwanted side effects and made it difficult to handle the cancellation properly.I looked into the source code of httpx and found that the problem was in the
aiter_rawandaiter_bytesfunctions in thehttpx/_client.pymodule. These functions useasync forto iterate over the response stream, but they do not catch theasyncio.CancelledErrorthat may be raised when the stream is cancelled. According to the [documentation] ofasyncio.CancelledError, this exception should be caught and either re-raised or suppressed. In this case, I think it would make sense to re-raise it as aGeneratorExit, which is the expected exception for generator termination.I suggest adding a
try-exceptblock around theasync forloop in theaiter_rawandaiter_bytesfunctions, like this:Beta Was this translation helpful? Give feedback.
All reactions