Skip to content

Commit

Permalink
Merge pull request #118 from Jylpah/dev-1.0
Browse files Browse the repository at this point in the history
version 1.2.1
  • Loading branch information
Jylpah authored Jan 1, 2024
2 parents f9ffb69 + 2106910 commit ab42ae0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "pyutils"
version = "1.2.0"
version = "1.2.1"
authors = [{ name = "Jylpah", email = "jylpah@gmail.com" }]
description = "Misc Python utils and classes"
readme = "README.md"
Expand Down
38 changes: 19 additions & 19 deletions src/pyutils/throttledclientsession.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,25 +160,25 @@ def stats_dict(self) -> dict[str, float | int]:
}
return res

# @classmethod
# def print_stats(cls, stats: dict[str, float | int]) -> str:
# try:
# rate_limit: float = stats["rate_limit"]
# rate: float = stats["rate"]
# count: float = stats["count"]
# errors: float = stats["errors"]

# rate_limit_str: str
# if rate_limit >= 1 or rate_limit == 0:
# rate_limit_str = f"{rate_limit:.1f} requests/sec"
# else:
# rate_limit_str = f"{1/rate_limit:.1f} secs/request"

# return f"rate limit: {rate_limit_str}, rate: {rate:.1f} request/sec, requests: {count:.0f}, errors: {errors:.0f}"
# except KeyError as err:
# return f"Incorrect stats format: {err}"
# except Exception as err:
# return f"Unexpected error: {err}"
@classmethod
def print_stats(cls, stats: dict[str, float | int]) -> str:
try:
rate_limit: float = stats["rate_limit"]
rate: float = stats["rate"]
count: float = stats["count"]
errors: float = stats["errors"]

rate_limit_str: str
if rate_limit >= 1 or rate_limit == 0:
rate_limit_str = f"{rate_limit:.1f} requests/sec"
else:
rate_limit_str = f"{1/rate_limit:.1f} secs/request"

return f"rate limit: {rate_limit_str}, rate: {rate:.1f} request/sec, requests: {count:.0f}, errors: {errors:.0f}"
except KeyError as err:
return f"Incorrect stats format: {err}"
except Exception as err:
return f"Unexpected error: {err}"

def reset_counters(self) -> dict[str, float | int]:
"""Reset rate counters and return current results"""
Expand Down
1 change: 1 addition & 0 deletions tests/test_throttledclientsession.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ async def test_3_get_json(server_url: str, json_path: str) -> None:
for _ in range(N):
if (_ := await get_url_JSON(session=session, url=url, retries=2)) is None:
assert False, "get_url_JSON() returned None"
ThrottledClientSession.print_stats(session.stats_dict) # type: ignore


@pytest.mark.skipif(
Expand Down

0 comments on commit ab42ae0

Please sign in to comment.