Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose setting multiple protocols and ports via the dask-scheduler CLI #6898

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions distributed/cli/dask_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

@click.command(context_settings=dict(ignore_unknown_options=True))
@click.option("--host", type=str, default="", help="URI, IP or hostname of this server")
@click.option("--port", type=int, default=None, help="Serving port")
@click.option("--port", type=str, default=None, help="Serving port")
@click.option(
"--interface",
type=str,
Expand Down Expand Up @@ -130,6 +130,7 @@
def main(
host,
port,
protocol,
bokeh_port,
show,
dashboard,
Expand Down Expand Up @@ -162,8 +163,26 @@ def main(
)
dashboard = bokeh

if protocol and "," in protocol:
protocol = protocol.split(",")

if port:
if "," in port:
port = [int(p) for p in port.split(",")]
else:
port = int(port)

if port is None and (not host or not re.search(r":\d", host)):
port = 8786
if isinstance(protocol, list):
port = [8786] + [0] * (len(protocol) - 1)
else:
port = 8786

if isinstance(protocol, list) or isinstance(port, list):
if (not isinstance(protocol, list) or not isinstance(port, list)) or len(
port
) != len(protocol):
raise ValueError("--protocol and --port must both be lists of equal length")

sec = {
k: v
Expand Down Expand Up @@ -202,6 +221,7 @@ async def run():
security=sec,
host=host,
port=port,
protocol=protocol,
dashboard=dashboard,
dashboard_address=dashboard_address,
http_prefix=dashboard_prefix,
Expand Down
16 changes: 16 additions & 0 deletions distributed/cli/tests/test_dask_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,22 @@ def test_dashboard_non_standard_ports(loop):
requests.get(f"http://localhost:{port2}/status/")


def test_multiple_protocols(loop):
port1 = open_port()
port2 = open_port()
with popen(
[
"dask-scheduler",
"--protocol=tcp,ws",
f"--port={port1},{port2}",
]
) as _:
with Client(f"tcp://127.0.0.1:{port1}", loop=loop):
pass
with Client(f"ws://127.0.0.1:{port2}", loop=loop):
pass


@pytest.mark.skipif(not LINUX, reason="Need 127.0.0.2 to mean localhost")
def test_dashboard_allowlist(loop):
pytest.importorskip("bokeh")
Expand Down