diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d4c1d1a1b6..968c79fad2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -60,7 +60,7 @@ repos: - id: no_optional - repo: https://github.com/astral-sh/ruff-pre-commit.git - rev: v0.13.3 + rev: v0.15.9 hooks: - id: ruff args: @@ -68,31 +68,31 @@ repos: - --fix # NOTE: When `--fix` is used, linting should be before ruff-format - repo: https://github.com/astral-sh/ruff-pre-commit.git - rev: v0.13.3 + rev: v0.15.9 hooks: - id: ruff-format alias: ruff-format-first-pass name: ruff-format (first pass) - repo: https://github.com/asottile/add-trailing-comma.git - rev: v3.2.0 + rev: v4.0.0 hooks: - id: add-trailing-comma - repo: https://github.com/astral-sh/ruff-pre-commit.git - rev: v0.13.3 + rev: v0.15.9 hooks: - id: ruff-format alias: ruff-format-second-pass name: ruff-format (second pass) - repo: https://github.com/Lucas-C/pre-commit-hooks.git - rev: v1.5.5 + rev: v1.5.6 hooks: - id: remove-tabs - repo: https://github.com/python-jsonschema/check-jsonschema.git - rev: 0.34.0 + rev: 0.37.1 hooks: - id: check-github-workflows files: ^\.github/workflows/[^/]+$ @@ -166,7 +166,7 @@ repos: - id: debug-statements - repo: https://github.com/adrienverge/yamllint.git - rev: v1.37.1 + rev: v1.38.0 hooks: - id: yamllint types: @@ -205,7 +205,7 @@ repos: - id: forbid-html-img-without-alt-text - repo: https://github.com/pre-commit/mirrors-mypy.git - rev: v1.18.2 + rev: v1.20.0 hooks: - id: mypy alias: mypy-py314 @@ -283,7 +283,7 @@ repos: pass_filenames: false - repo: https://github.com/pre-commit/mirrors-mypy.git - rev: v1.18.2 + rev: v1.20.0 hooks: - id: mypy alias: mypy-stubtest @@ -317,7 +317,7 @@ repos: $ - repo: https://github.com/PyCQA/pylint.git - rev: v3.3.9 + rev: v4.0.5 hooks: - id: pylint additional_dependencies: diff --git a/cheroot/server.py b/cheroot/server.py index 27e9173b15..284cf17c72 100644 --- a/cheroot/server.py +++ b/cheroot/server.py @@ -1670,49 +1670,65 @@ def clear_stats(self): self.stats = { 'Enabled': False, 'Bind Address': lambda s: repr(self.bind_addr), - 'Run time': lambda s: ((not s['Enabled']) and -1) - or self.runtime(), + 'Run time': lambda s: ( + ((not s['Enabled']) and -1) or self.runtime() + ), 'Accepts': 0, 'Accepts/sec': lambda s: s['Accepts'] / self.runtime(), 'Queue': lambda s: getattr(self.requests, 'qsize', None), 'Threads': lambda s: len(getattr(self.requests, '_threads', [])), 'Threads Idle': lambda s: getattr(self.requests, 'idle', None), 'Socket Errors': 0, - 'Requests': lambda s: ((not s['Enabled']) and -1) - or sum( - (w['Requests'](w) for w in s['Worker Threads'].values()), - 0, + 'Requests': lambda s: ( + ((not s['Enabled']) and -1) + or sum( + (w['Requests'](w) for w in s['Worker Threads'].values()), + 0, + ) ), - 'Bytes Read': lambda s: ((not s['Enabled']) and -1) - or sum( - (w['Bytes Read'](w) for w in s['Worker Threads'].values()), - 0, + 'Bytes Read': lambda s: ( + ((not s['Enabled']) and -1) + or sum( + (w['Bytes Read'](w) for w in s['Worker Threads'].values()), + 0, + ) ), - 'Bytes Written': lambda s: ((not s['Enabled']) and -1) - or sum( - (w['Bytes Written'](w) for w in s['Worker Threads'].values()), - 0, + 'Bytes Written': lambda s: ( + ((not s['Enabled']) and -1) + or sum( + ( + w['Bytes Written'](w) + for w in s['Worker Threads'].values() + ), + 0, + ) ), - 'Work Time': lambda s: ((not s['Enabled']) and -1) - or sum( - (w['Work Time'](w) for w in s['Worker Threads'].values()), - 0, + 'Work Time': lambda s: ( + ((not s['Enabled']) and -1) + or sum( + (w['Work Time'](w) for w in s['Worker Threads'].values()), + 0, + ) ), - 'Read Throughput': lambda s: ((not s['Enabled']) and -1) - or sum( - ( - w['Bytes Read'](w) / (w['Work Time'](w) or 1e-6) - for w in s['Worker Threads'].values() - ), - 0, + 'Read Throughput': lambda s: ( + ((not s['Enabled']) and -1) + or sum( + ( + w['Bytes Read'](w) / (w['Work Time'](w) or 1e-6) + for w in s['Worker Threads'].values() + ), + 0, + ) ), - 'Write Throughput': lambda s: ((not s['Enabled']) and -1) - or sum( - ( - w['Bytes Written'](w) / (w['Work Time'](w) or 1e-6) - for w in s['Worker Threads'].values() - ), - 0, + 'Write Throughput': lambda s: ( + ((not s['Enabled']) and -1) + or sum( + ( + w['Bytes Written'](w) / (w['Work Time'](w) or 1e-6) + for w in s['Worker Threads'].values() + ), + 0, + ) ), 'Worker Threads': {}, } diff --git a/cheroot/workers/threadpool.py b/cheroot/workers/threadpool.py index 269574514c..31bc004b4f 100644 --- a/cheroot/workers/threadpool.py +++ b/cheroot/workers/threadpool.py @@ -71,30 +71,40 @@ def __init__(self, server): self.start_time = None self.work_time = 0 self.stats = { - 'Requests': lambda s: self.requests_seen - + ( - (self.start_time is None and trueyzero) - or self.conn.requests_seen + 'Requests': lambda s: ( + self.requests_seen + + ( + (self.start_time is None and trueyzero) + or self.conn.requests_seen + ) + ), + 'Bytes Read': lambda s: ( + self.bytes_read + + ( + (self.start_time is None and trueyzero) + or self.conn.rfile.bytes_read + ) ), - 'Bytes Read': lambda s: self.bytes_read - + ( - (self.start_time is None and trueyzero) - or self.conn.rfile.bytes_read + 'Bytes Written': lambda s: ( + self.bytes_written + + ( + (self.start_time is None and trueyzero) + or self.conn.wfile.bytes_written + ) + ), + 'Work Time': lambda s: ( + self.work_time + + ( + (self.start_time is None and trueyzero) + or time.time() - self.start_time + ) ), - 'Bytes Written': lambda s: self.bytes_written - + ( - (self.start_time is None and trueyzero) - or self.conn.wfile.bytes_written + 'Read Throughput': lambda s: ( + s['Bytes Read'](s) / (s['Work Time'](s) or 1e-6) ), - 'Work Time': lambda s: self.work_time - + ( - (self.start_time is None and trueyzero) - or time.time() - self.start_time + 'Write Throughput': lambda s: ( + s['Bytes Written'](s) / (s['Work Time'](s) or 1e-6) ), - 'Read Throughput': lambda s: s['Bytes Read'](s) - / (s['Work Time'](s) or 1e-6), - 'Write Throughput': lambda s: s['Bytes Written'](s) - / (s['Work Time'](s) or 1e-6), } threading.Thread.__init__(self)