From 915d2abe28410d2e94745da9fcf01d507862eb3e Mon Sep 17 00:00:00 2001 From: Skrattoune <56255427+Skrattoune@users.noreply.github.com> Date: Mon, 12 Feb 2024 16:27:34 +0100 Subject: [PATCH] preventing ZeroDivisionError in throughput 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 --- huey_monitor/humanize.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/huey_monitor/humanize.py b/huey_monitor/humanize.py index 65adffe..19f1be1 100644 --- a/huey_monitor/humanize.py +++ b/huey_monitor/humanize.py @@ -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) if rate > 1: rate_str = format_sizeof(rate, suffix=suffix, divisor=divisor)