diff --git a/distributed/scheduler.py b/distributed/scheduler.py index a026e897ed6..225a11ee86e 100644 --- a/distributed/scheduler.py +++ b/distributed/scheduler.py @@ -32,7 +32,16 @@ ) from contextlib import suppress from functools import partial -from typing import TYPE_CHECKING, Any, ClassVar, Literal, NamedTuple, cast, overload +from typing import ( + TYPE_CHECKING, + Any, + ClassVar, + Final, + Literal, + NamedTuple, + cast, + overload, +) import psutil import tornado.web @@ -413,7 +422,7 @@ class WorkerState: #: This worker's unique key. This can be its connected address #: (such as ``"tcp://127.0.0.1:8891"``) or an alias (such as ``"alice"``). - address: str + address: Final[str] pid: int name: Hashable @@ -513,6 +522,9 @@ class WorkerState: #: on the worker. needs_what: dict[TaskState, int] + #: The hostname / IP address identifying the machine this worker is on. + host: Final[str] + __slots__ = tuple(__annotations__) def __init__( @@ -564,6 +576,7 @@ def __init__( self.needs_what = {} self._network_occ = 0 self._occupancy_cache = None + self.host = get_address_host(self.address) def __hash__(self) -> int: return self._hash @@ -584,10 +597,6 @@ def has_what(self) -> Set[TaskState]: """ return self._has_what.keys() - @property - def host(self) -> str: - return get_address_host(self.address) - @property def memory(self) -> MemoryState: """Polished memory metrics for the worker.