diff --git a/distributed/client.py b/distributed/client.py
index d630eb8583d..78dbc91a524 100644
--- a/distributed/client.py
+++ b/distributed/client.py
@@ -53,6 +53,7 @@
)
from .diagnostics.plugin import UploadFile, WorkerPlugin, _get_worker_plugin_name
from .metrics import time
+from .objects import HasWhat, WhoHas
from .protocol import to_serialize
from .protocol.pickle import dumps, loads
from .publish import Datasets
@@ -3202,7 +3203,7 @@ def who_has(self, futures=None, **kwargs):
keys = list(map(stringify, {f.key for f in futures}))
else:
keys = None
- return self.sync(self.scheduler.who_has, keys=keys, **kwargs)
+ return WhoHas(self.sync(self.scheduler.who_has, keys=keys, **kwargs))
def has_what(self, workers=None, **kwargs):
"""Which keys are held by which workers
@@ -3236,7 +3237,7 @@ def has_what(self, workers=None, **kwargs):
workers = list(workers)
if workers is not None and not isinstance(workers, (tuple, list, set)):
workers = [workers]
- return self.sync(self.scheduler.has_what, workers=workers, **kwargs)
+ return HasWhat(self.sync(self.scheduler.has_what, workers=workers, **kwargs))
def processing(self, workers=None):
"""The tasks currently running on each worker
diff --git a/distributed/objects.py b/distributed/objects.py
new file mode 100644
index 00000000000..d53860514ec
--- /dev/null
+++ b/distributed/objects.py
@@ -0,0 +1,67 @@
+"""This file contains custom objects.
+These are mostly regular objects with more useful _repr_ and _repr_html_ methods."""
+
+
+class HasWhat(dict):
+ """A dictionary of all workers and which keys that worker has."""
+
+ def _repr_html_(self):
+ rows = ""
+
+ for worker, keys in sorted(self.items()):
+ summary = ""
+ for key in keys:
+ summary += f"""
{key} |
"""
+
+ rows += f"""
+ {worker} |
+ {len(keys)} |
+
+
+ Expand
+
+
+ |
+
"""
+
+ output = f"""
+
+
+ Worker |
+ Key count |
+ Key list |
+
+ {rows}
+
+ """
+
+ return output
+
+
+class WhoHas(dict):
+ """A dictionary of all keys and which workers have that key."""
+
+ def _repr_html_(self):
+ rows = ""
+
+ for title, keys in sorted(self.items()):
+ rows += f"""
+ {title} |
+ {len(keys)} |
+ {", ".join(keys)} |
+
"""
+
+ output = f"""
+
+
+ Key |
+ Copies |
+ Workers |
+
+ {rows}
+
+ """
+
+ return output