dask-distributed¶
cluster
¶
Connecting to the Compose cluster, with a local fallback.
Every example opens its cluster through :func:connect. When the Compose
cluster is up it returns a client wired to the containers; when it is not, it
falls back to an in-process LocalCluster and says so. That keeps the
examples runnable on a machine without Docker while still demonstrating the
real thing when the cluster is running -- the repository rule that an example
depending on a server must still run, and explain itself, when unconfigured.
The scheduler address comes from DASK_SCHEDULER_ADDRESS so the same code
works against a remote cluster without edits.
Classes¶
ClusterSession
dataclass
¶
A connected client plus how it was obtained.
Attributes:
| Name | Type | Description |
|---|---|---|
client |
Any
|
The connected |
mode |
str
|
Either |
address |
str
|
The scheduler address actually in use. |
Source code in dask-distributed/src/ocs_stack_dask_distributed/cluster.py
Attributes¶
is_compose
property
¶
Whether this session is talking to the Compose cluster.
Methods:¶
banner()
¶
Return a one-line description of the connection for example output.
Source code in dask-distributed/src/ocs_stack_dask_distributed/cluster.py
close()
¶
Close the client and, for the fallback, the cluster it created.
Source code in dask-distributed/src/ocs_stack_dask_distributed/cluster.py
__enter__()
¶
__exit__(exc_type, exc, tb)
¶
Functions:¶
scheduler_reachable(address=SCHEDULER_ADDRESS, timeout=1.0)
¶
Report whether a scheduler is accepting TCP connections at an address.
A plain socket probe rather than a dask connection: it answers in milliseconds when nothing is listening, so examples do not hang waiting on a cluster that was never started.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
address
|
str
|
Scheduler address to probe. |
SCHEDULER_ADDRESS
|
timeout
|
float
|
Seconds to wait for the TCP handshake. |
1.0
|
Returns:
| Type | Description |
|---|---|
bool
|
True when something accepts a connection, False otherwise. |
Source code in dask-distributed/src/ocs_stack_dask_distributed/cluster.py
wait_for_scheduler(address=SCHEDULER_ADDRESS, timeout=120.0)
¶
Block until the scheduler accepts connections, for use by make up.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
address
|
str
|
Scheduler address to poll. |
SCHEDULER_ADDRESS
|
timeout
|
float
|
Total seconds to keep trying before giving up. |
120.0
|
Returns:
| Type | Description |
|---|---|
bool
|
True once the scheduler answers. |
Raises:
| Type | Description |
|---|---|
TimeoutError
|
If the scheduler never answers within the timeout. |
Source code in dask-distributed/src/ocs_stack_dask_distributed/cluster.py
connect(address=SCHEDULER_ADDRESS, *, allow_fallback=True)
¶
Connect to the Compose cluster, or to a LocalCluster if it is not up.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
address
|
str
|
Scheduler address to try first. |
SCHEDULER_ADDRESS
|
allow_fallback
|
bool
|
When False, refuse to start a local cluster and raise instead -- used by examples that only make sense against real containers. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
ClusterSession
|
class: |
Raises:
| Type | Description |
|---|---|
ConnectionError
|
If the cluster is unreachable and fallback is off. |
Source code in dask-distributed/src/ocs_stack_dask_distributed/cluster.py
describe_workers(client)
¶
Summarize the cluster's workers for printing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Any
|
A connected |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
One dict per worker with its address, thread count, memory limit in |
list[dict[str, Any]]
|
GiB, and the host it runs on -- in a container cluster the hosts are |
list[dict[str, Any]]
|
distinct, which is the whole point. |