Skip to content

Commit bf6d37f

Browse files
authored
Fix workers / threads / memory displayed in client repr (#9066)
1 parent f56b02e commit bf6d37f

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

distributed/client.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,18 +1343,16 @@ def __repr__(self):
13431343
info = self._scheduler_identity
13441344
addr = info.get("address")
13451345
if addr:
1346-
workers = info.get("workers", {})
1347-
nworkers = len(workers)
1348-
nthreads = sum(w["nthreads"] for w in workers.values())
1346+
nworkers = info.get("n_workers", 0)
1347+
nthreads = info.get("total_threads", 0)
13491348
text = "<%s: %r processes=%d threads=%d" % (
13501349
self.__class__.__name__,
13511350
addr,
13521351
nworkers,
13531352
nthreads,
13541353
)
1355-
memory = [w["memory_limit"] for w in workers.values()]
1356-
if all(memory):
1357-
text += ", memory=" + format_bytes(sum(memory))
1354+
memory = info.get("total_memory", 0)
1355+
text += ", memory=" + format_bytes(memory)
13581356
text += ">"
13591357
return text
13601358

distributed/tests/test_client.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2118,12 +2118,21 @@ async def test_badly_serialized_input_stderr(capsys, c):
21182118
],
21192119
)
21202120
def test_repr(loop, func):
2121-
with cluster(nworkers=3, worker_kwargs={"memory_limit": "2 GiB"}) as (s, [a, b, c]):
2121+
nworkers = 6
2122+
with cluster(nworkers=nworkers, worker_kwargs={"memory_limit": "2 GiB"}) as (
2123+
s,
2124+
*workers,
2125+
):
21222126
with Client(s["address"], loop=loop) as c:
2127+
# NOTE: Intentionally testing when we have more workers than the default
2128+
# in `client.scheduler_info()` (xref https://github.com/dask/distributed/issues/9065)
2129+
info = c.scheduler_info()
2130+
assert len(info["workers"]) < nworkers
2131+
21232132
text = func(c)
21242133
assert c.scheduler.address in text
2125-
assert "threads=3" in text or "Total threads: </strong>" in text
2126-
assert "6.00 GiB" in text
2134+
assert f"threads={nworkers}" in text or "Total threads: </strong>" in text
2135+
assert f"{2 * nworkers}.00 GiB" in text
21272136
if "<table" not in text:
21282137
assert len(text) < 80
21292138

0 commit comments

Comments
 (0)