-
Notifications
You must be signed in to change notification settings - Fork 20
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
Conversation
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
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.
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) |
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.
Hm. Think this is not a good solution, because it calculate with wrong values...
What about:
if elapsed_sec==0:
return '~'
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.
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.
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.
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?
fixed in #148 |
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
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