diff --git a/distributed/cli/dask_scheduler.py b/distributed/cli/dask_scheduler.py index 8ef9a678ae1..a928dbfe83b 100755 --- a/distributed/cli/dask_scheduler.py +++ b/distributed/cli/dask_scheduler.py @@ -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, @@ -130,6 +130,8 @@ def main( host, port, + protocol, + interface, bokeh_port, show, dashboard, @@ -162,8 +164,29 @@ def main( ) dashboard = bokeh + if interface and "," in interface: + interface = interface.split(",") + + 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 @@ -202,6 +225,8 @@ async def run(): security=sec, host=host, port=port, + protocol=protocol, + interface=interface, dashboard=dashboard, dashboard_address=dashboard_address, http_prefix=dashboard_prefix, diff --git a/distributed/cli/tests/test_dask_scheduler.py b/distributed/cli/tests/test_dask_scheduler.py index 89376429aad..06303458eac 100644 --- a/distributed/cli/tests/test_dask_scheduler.py +++ b/distributed/cli/tests/test_dask_scheduler.py @@ -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")