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

Conversation

Skrattoune
Copy link
Contributor

I just spent almost one week trying to figure out the origin of a seamingly random error which afected my code ...

sometime, the difference between execute_dt and update_dt was so small that dividing by the difference led to a ZeroDivisionError when displaying the task name in task log...

stupid and difficult to spot error corrected through this PR

I just spent almost one week trying to figure out the origin of a seamingly random error which afected my code ...

sometime, the difference between execute_dt and update_dt was so small that dividing by the difference led to a ZeroDivisionError when displaying the task name in task log...

stupid and difficult to spot error corrected through this PR
Copy link
Contributor Author

@Skrattoune Skrattoune left a comment

Choose a reason for hiding this comment

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

no impact on anything except prevention of unwanted and difficult to plan-for ZeroDivisionError
so I don't see any issue for merging to main

@@ -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?

@jedie
Copy link
Collaborator

jedie commented Feb 27, 2024

fixed in #148

@jedie jedie closed this Feb 27, 2024
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 67.95%. Comparing base (2d37f25) to head (915d2ab).
Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #143   +/-   ##
=======================================
  Coverage   67.95%   67.95%           
=======================================
  Files          36       36           
  Lines         749      749           
  Branches       88       88           
=======================================
  Hits          509      509           
  Misses        240      240           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants