Skip to content

Avoid handle BaseException just for cover async task cancellation. #805

Discussion options

You must be logged in to vote

I think the most graceful way to do what you're attempting here would be adding the following in _syncronization.py...

EXCEPTION_OR_CANCELLED = (Exception,)

try:
    import trio  # trio support is available to httpcore
    EXCEPTION_OR_CANCELLED += (trio.CancelledError,)
except ImportError:
    pass

try:
    import anyio  # asyncio support is available to httpcore
    import asyncio
    EXCEPTION_OR_CANCELLED += (asyncio.Cancelled,)
except ImportError:
    pass

And then import and use EXCEPTION_OR_CANCELLED in the existing BaseException cases...

try:
    ...
except EXCEPTION_OR_CANCELLED as exc:
    ...

The would seem to me to be the simplest approach that would work fine for both the _…

Replies: 2 comments 12 replies

Comment options

You must be logged in to vote
11 replies
@T-256
Comment options

@karpetrosyan
Comment options

@T-256
Comment options

@tomchristie
Comment options

@T-256
Comment options

Comment options

You must be logged in to vote
1 reply
@T-256
Comment options

Answer selected by T-256
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants