-
Notifications
You must be signed in to change notification settings - Fork 581
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change TimeoutError
=> asyncio.TimeoutError
#1666
Change TimeoutError
=> asyncio.TimeoutError
#1666
Conversation
The documentation is not available anymore as the PR was closed or merged. |
Hi @matthewgrossman thanks for opening this PR and for the clear explanation of the problem. I've never encountered this problem as I was testing async TimeoutError only locally and on Python 3.11. The fix you propose looks good to me.
We want to support Python3.8+ so this PR is definitely helpful! |
Tests are flaky at the moment. I'll merge this PR right now as the tests are not related to your PR. Thanks for your contribution :) |
Great, glad it's helpful! Let me know if you want anything else in the PR (I see now that CI does run otherwise it's ready to merge away 🎉 |
@matthewgrossman Thanks for suggesting! Indeed adding a unit test would be good to as well. I would add it to test_inference_async_client.py. Let me know if you need help/guidance/review for that :) |
…man/huggingface_hub into mg/fix-asyncio-timeouterror
I locally removed the fix, just to confirm the test validates the behavior:
When I remove the local changes, it starts to pass (which we should of course see once you approve the workflow for CI as well). Feel free to give any feedback on the test I wrote! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a very clean and complete PR, thanks @matthewgrossman! 🎉 Test looks good to me. Fast and simple as I like them ❤️
I've triggered the CI. Let's wait until it's ✔️ and I'll merge :)
EDIT: all green!
Problem
I'm currently running python 3.9 with the
huggingface_hub
AsyncInferenceClient
library.When a request times out, the library is supposed to catch the
TimeoutError
and reraise a customInferenceTimeoutError
: https://github.com/huggingface/huggingface_hub/blob/3734d74/src/huggingface_hub/inference/_generated/_async_client.py#L230-L233However, when these exceptions occurred for me, I'd never catch the custom error; I'd get an
asyncio.TimeoutError
.The reason this is happening is because a
TimeoutError
andasyncio.TimeoutError
are different exceptions in python3.9:Because this library never catches the actual error, it never calls
await client.close()
. This doesn't have huge consequence, but it means I get noisy error logs about unclosed sessions (source):Solution
I think the easiest fix here is to simply catch
asyncio.TimeoutError
in theAsyncInferenceClient
timeout-path. Because newer versions of python alias this library, I see no reasons why it wouldn't be forward-compatible eitherCommentary
I can add some testcases / reproducible steps to this, but want to make sure the repo owners are amenable to this change. I did read the contributing docs, but I just want to make sure the repo doesn't have a policy around "only support python version 3.X+" or something