Skip to content
This repository has been archived by the owner on Dec 17, 2022. It is now read-only.

Commit

Permalink
Prevent potential ZeroDivisionError in rate_per_second
Browse files Browse the repository at this point in the history
  • Loading branch information
impredicative committed Mar 7, 2022
1 parent 0219317 commit b44261a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions bitlyshortener/shortener.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def usage(self) -> float:
usages = list(mapper(self._usage, tokens))
time_used = time.monotonic() - start_time
usage = sum(u["used"] for u in usages) / sum(u["limit"] for u in usages)
rate_per_second = num_tokens / time_used
rate_per_second = (num_tokens / time_used) if (time_used != 0) else float("inf")
log.info(
"%s retrieved usage of %s for %s tokens%s in %.1fs at a rate of %s/s.",
strategy_desc,
Expand Down Expand Up @@ -267,7 +267,7 @@ def shorten_urls(self, long_urls: List[str]) -> List[str]:
time_used = time.monotonic() - start_time
num_short_urls = len(short_urls)
assert num_long_urls == num_short_urls
rate_per_second = num_short_urls / time_used
rate_per_second = (num_short_urls / time_used) if (time_used != 0) else float("inf")
log.info(
"%s retrieved %s short URLs%s in %.1fs at a rate of %s/s. %s",
strategy_desc,
Expand Down

0 comments on commit b44261a

Please sign in to comment.