Skip to content
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

preventing ZeroDivisionError in throughput #143

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion huey_monitor/humanize.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ def throughput(num, elapsed_sec, suffix='', divisor=1000) -> str:
if suffix:
return f'0/{suffix}'
return '0'
rate = num / elapsed_sec
# need to prevent ZeroDivisionError:
rate = num / max(elapsed_sec, 0.001)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm. Think this is not a good solution, because it calculate with wrong values...

What about:

if elapsed_sec==0:
    return '~'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe

if elapsed_sec==0:
    return '∞'

🤓

On a more serious note I'd also prefer not to use a hardcoded "minimum" time delta and rather return something else in this rare case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem for me Jedie.

The hardcoded value of one millisecond was for me a good approximation
Of minimum timing that could be recorded

Do you want me to do the change in the PR or you do it yourself?

We go for the infinite symbol then?


if rate > 1:
rate_str = format_sizeof(rate, suffix=suffix, divisor=divisor)
Expand Down
Loading