Handle async cancelled error explicitly
Summary
Discussed in https://github.com/encode/httpcore/discussions/805
Checklist
- [x] I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
- [ ] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
- [ ] I've updated the documentation accordingly.
We'd need to change in both
httpcore/_asyncandhttpcore/_syncand ensure them match.
As what's said in #806, I think this could be ignored in unasync.py to avoid extra unuseful load. (Task behaviors not defined on threads.)
But still I'm waiting to get proper response from team to choose final implementation for sync part.
Is this solution respects such cases?
because the user may catch the keyboardinterrupt in his code and continue to use httpcore.ConnectionPool.
Is this solution respects such cases?
No, #812 will respect.
Actually this PR can expose why current cleanup system is not well implemented.
No, #812 will respect.
Do we want to marge this PR when we know it will break programs that handle BaseExceptions like KeyboardInterrupt?
Do we want to marge this PR when we know it will break programs that handle
BaseExceptionslikeKeyboardInterrupt?
Yes. because still some of cleanups doesn't handle BaseException in codebase:
-
https://github.com/encode/httpcore/blob/94ffb33cf378e41662c90615458db9e42b43cad5/httpcore/_async/connection.py#L97-L100
-
https://github.com/encode/httpcore/blob/94ffb33cf378e41662c90615458db9e42b43cad5/httpcore/_async/http2.py#L441-L453
-
https://github.com/encode/httpcore/blob/94ffb33cf378e41662c90615458db9e42b43cad5/httpcore/_async/http2.py#L470-L482
-
https://github.com/encode/httpcore/blob/94ffb33cf378e41662c90615458db9e42b43cad5/httpcore/_async/socks_proxy.py#L294-L297
-
https://github.com/encode/httpcore/blob/94ffb33cf378e41662c90615458db9e42b43cad5/httpcore/_backends/anyio.py#L76-L79
-
https://github.com/encode/httpcore/blob/94ffb33cf378e41662c90615458db9e42b43cad5/httpcore/_backends/trio.py#L78-L81
-
plus, same things in
_syncpart.
And also notice few BaseException was introduced in https://github.com/encode/httpcore/pull/726, so before that we were not supporting KeyboardInterrupt:
Should we consider convert exception handlings in https://github.com/encode/httpcore/pull/811#issuecomment-1727720109 to EXCEPTION_OR_CANCELLED?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.