Skip to content

Commit

Permalink
to_dict
Browse files Browse the repository at this point in the history
  • Loading branch information
crusaderky committed Mar 5, 2022
1 parent 41d6e88 commit 825112a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
11 changes: 9 additions & 2 deletions distributed/tests/test_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3272,7 +3272,7 @@ async def test_Worker__to_dict(c, s, a):
x = c.submit(inc, 1, key="x")
await wait(x)
d = a._to_dict()
assert d.keys() == {
assert set(d) == {
"type",
"id",
"scheduler",
Expand All @@ -3288,7 +3288,13 @@ async def test_Worker__to_dict(c, s, a):
"in_flight_workers",
"log",
"tasks",
"memory_manager",
"data",
"max_spill",
"memory_limit",
"memory_monitor_interval",
"memory_pause_fraction",
"memory_spill_fraction",
"memory_target_fraction",
"logs",
"config",
"incoming_transfer_log",
Expand All @@ -3297,6 +3303,7 @@ async def test_Worker__to_dict(c, s, a):
"pending_data_per_worker",
}
assert d["tasks"]["x"]["key"] == "x"
assert d["data"] == ["x"]


@gen_cluster(client=True, nthreads=[("", 1)])
Expand Down
5 changes: 1 addition & 4 deletions distributed/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1213,16 +1213,13 @@ def _to_dict(self, *, exclude: Container[str] = ()) -> dict:
"in_flight_workers": self.in_flight_workers,
"log": self.log,
"tasks": self.tasks,
"memory_limit": self.memory_manager.memory_limit,
"memory_target_fraction": self.memory_target_fraction,
"memory_spill_fraction": self.memory_spill_fraction,
"memory_pause_fraction": self.memory_pause_fraction,
"logs": self.get_logs(),
"config": dask.config.config,
"incoming_transfer_log": self.incoming_transfer_log,
"outgoing_transfer_log": self.outgoing_transfer_log,
}
info.update(extra)
info.update(self.memory_manager._to_dict(exclude=exclude))
info = {k: v for k, v in info.items() if k not in exclude}
return recursive_to_dict(info, exclude=exclude)

Expand Down
9 changes: 9 additions & 0 deletions distributed/worker_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,15 @@ async def _maybe_spill(self, worker: Worker, memory: int) -> None:
format_bytes(total_spilled),
)

def _to_dict(self, *, exclude: Container[str] = ()) -> dict:
info = {
k: v
for k, v in self.__dict__.items()
if not k.startswith("_") and k != "data" and k not in exclude
}
info["data"] = list(self.data)
return info


class NannyMemoryManager:
memory_limit: int | None
Expand Down

0 comments on commit 825112a

Please sign in to comment.