fix: close progress bars on exception in io.py#422
fix: close progress bars on exception in io.py#422kredd2506 wants to merge 1 commit intogoogle:mainfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Wrap progress bar usage in try/finally blocks in save_annotated_documents and download_text_from_url so progress_bar.close() is always called even when an exception is raised mid-iteration. Fixes google#401
22b2e88 to
9f1047f
Compare
|
Your branch is 1 commits behind git fetch origin main
git merge origin/main
git pushNote: Enable "Allow edits by maintainers" to allow automatic updates. |
|
Your branch is 3 commits behind git fetch origin main
git merge origin/main
git pushNote: Enable "Allow edits by maintainers" to allow automatic updates. |
Description
Wrap
tqdmprogress bar usage intry/finallyblocks in two functions inlangextract/io.pyso thatprogress_bar.close()is always called, even when an exception is raised mid-iteration.Location 1 —
save_annotated_documents: If theannotated_documentsgenerator raises (e.g. anInferenceOutputErrorfrom a failed LLM call), the original code left the progress bar open sinceprogress_bar.close()sat unconditionally after thewith open(...)block.Location 2 —
download_text_from_url: Ifresponse.iter_content()raises arequests.RequestException(e.g. a connection reset mid-download), theexceptblock re-raised without callingprogress_bar.close().Fixes #401
Bug fix
How Has This Been Tested?
Ran the existing test suite (excluding the pre-existing
openaiimport failure unrelated to this change):Also manually verified with a generator that raises mid-stream — confirmed
progress_bar.close()is called in both the exception and success paths.Checklist:
pylintover the affected code.