Skip to content

Commit e2dbf8b

Browse files
jcristjrbourbeau
authored andcommitted
Pass host through LocalCluster to workers (dask#5427)
Previously the `host` parameter to `LocalCluster` would only be forwarded to `Scheduler` instances and not `Worker`/`Nanny` instances, leading to workers listening on non-localhost in some configurations. This fixes that and adds a test. Co-authored-by: James Bourbeau <[email protected]>
1 parent 9f1e3ad commit e2dbf8b

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

distributed/deploy/local.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ def __init__(
198198

199199
worker_kwargs.update(
200200
{
201+
"host": host,
201202
"nthreads": threads_per_worker,
202203
"services": worker_services,
203204
"dashboard_address": worker_dashboard_address,

distributed/deploy/tests/test_local.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from distutils.version import LooseVersion
88
from threading import Lock
99
from time import sleep
10+
from urllib.parse import urlparse
1011

1112
import pytest
1213
import tornado
@@ -1100,3 +1101,20 @@ async def test_cluster_info_sync():
11001101

11011102
info = cluster.scheduler.get_metadata(keys=["cluster-manager-info"])
11021103
assert info["foo"] == "bar"
1104+
1105+
1106+
@pytest.mark.asyncio
1107+
@pytest.mark.parametrize("host", [None, "127.0.0.1"])
1108+
@pytest.mark.parametrize("use_nanny", [True, False])
1109+
async def test_cluster_host_used_throughout_cluster(host, use_nanny):
1110+
"""Ensure that the `host` kwarg is propagated through scheduler, nanny, and workers"""
1111+
async with LocalCluster(host=host, asynchronous=True) as cluster:
1112+
url = urlparse(cluster.scheduler_address)
1113+
assert url.hostname == "127.0.0.1"
1114+
for worker in cluster.workers.values():
1115+
url = urlparse(worker.address)
1116+
assert url.hostname == "127.0.0.1"
1117+
1118+
if use_nanny:
1119+
url = urlparse(worker.process.worker_address)
1120+
assert url.hostname == "127.0.0.1"

0 commit comments

Comments
 (0)