Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,39 +60,39 @@ 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:
# Ref: https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
- --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/[^/]+$
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
80 changes: 48 additions & 32 deletions cheroot/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': {},
}
Expand Down
50 changes: 30 additions & 20 deletions cheroot/workers/threadpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Loading