Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pw_console: Fix progress bar division by zero
In some cases it is possible to render a pw_console progress bar while the elapsed time is still zero. This causes a divide by zero error: File ".../python-venv/lib/site-packages/prompt_toolkit/shortcuts/progress_bar/formatters.py", line 325, in <listcomp> len(f"{c.items_completed / c.time_elapsed.total_seconds():.2f}") Exception float division by zero The background on why this is an issue is that pw_console removes the required context manager of prompt_toolkits progress bar implementation: https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/shortcuts/progress_bar/base.py#L6 So new runtime errors are possible depending on how the pw_console start_progress and update_progress functions are used. https://cs.opensource.google/pigweed/pigweed/+/main:pw_console/py/pw_console/progress_bar/__init__.py Change-Id: Ifb81038bc838a919f72c2d8f86509bb35edb5016 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/233033 Docs-Not-Needed: Anthony DiGirolamo <[email protected]> Pigweed-Auto-Submit: Anthony DiGirolamo <[email protected]> Lint: Lint 🤖 <[email protected]> Commit-Queue: Auto-Submit <[email protected]> Presubmit-Verified: CQ Bot Account <[email protected]> Reviewed-by: William Abajian <[email protected]>
- Loading branch information