Repository: dask/distributed

Issue:
SSHCluster fails in non-bash compatible shells
SSHCluster fails to propagate `DASK_INTERNAL_INHERIT_CONFIG` variable to scheduler and workers 
 using non-bash compatible shells. 

I suggest to pass this in the `env` keyword in `asyncssh.connection.create_process` instead of embedding it in the process command string to avoid handling different shell syntax for setting variables. 




Discussion:

Resolving patch:
diff --git a/distributed/deploy/ssh.py b/distributed/deploy/ssh.py
--- a/distributed/deploy/ssh.py
+++ b/distributed/deploy/ssh.py
@@ -86,22 +86,38 @@ async def start(self):
         import asyncssh  # import now to avoid adding to module startup time
 
         self.connection = await asyncssh.connect(self.address, **self.connect_options)
-        self.proc = await self.connection.create_process(
-            " ".join(
-                [
-                    'DASK_INTERNAL_INHERIT_CONFIG="%s"'
-                    % serialize_for_cli(dask.config.global_config),
-                    sys.executable,
-                    "-m",
-                    self.worker_module,
-                    self.scheduler,
-                    "--name",
-                    str(self.name),
-                ]
-                + cli_keywords(self.kwargs, cls=_Worker, cmd=self.worker_module)
+
+        result = await self.connection.run("uname")
+        if result.exit_status == 0:
+            set_env = 'env DASK_INTERNAL_INHERIT_CONFIG="{}"'.format(
+                serialize_for_cli(dask.config.global_config)
             )
+        else:
+            result = await self.connection.run("cmd /c ver")
+            if result.exit_status == 0:
+                set_env = "set DASK_INTERNAL_INHERIT_CONFIG={} &&".format(
+                    serialize_for_cli(dask.config.global_config)
+                )
+            else:
+                raise Exception(
+                    "Worker failed to set DASK_INTERNAL_INHERIT_CONFIG variable "
+                )
+
+        cmd = " ".join(
+            [
+                set_env,
+                sys.executable,
+                "-m",
+                self.worker_module,
+                self.scheduler,
+                "--name",
+                str(self.name),
+            ]
+            + cli_keywords(self.kwargs, cls=_Worker, cmd=self.worker_module)
         )
 
+        self.proc = await self.connection.create_process(cmd)
+
         # We watch stderr in order to get the address, then we return
         while True:
             line = await self.proc.stderr.readline()
@@ -144,18 +160,27 @@ async def start(self):
 
         self.connection = await asyncssh.connect(self.address, **self.connect_options)
 
-        self.proc = await self.connection.create_process(
-            " ".join(
-                [
-                    'DASK_INTERNAL_INHERIT_CONFIG="%s"'
-                    % serialize_for_cli(dask.config.global_config),
-                    sys.executable,
-                    "-m",
-                    "distributed.cli.dask_scheduler",
-                ]
-                + cli_keywords(self.kwargs, cls=_Scheduler)
+        result = await self.connection.run("uname")
+        if result.exit_status == 0:
+            set_env = 'env DASK_INTERNAL_INHERIT_CONFIG="{}"'.format(
+                serialize_for_cli(dask.config.global_config)
             )
+        else:
+            result = await self.connection.run("cmd /c ver")
+            if result.exit_status == 0:
+                set_env = "set DASK_INTERNAL_INHERIT_CONFIG={} &&".format(
+                    serialize_for_cli(dask.config.global_config)
+                )
+            else:
+                raise Exception(
+                    "Scheduler failed to set DASK_INTERNAL_INHERIT_CONFIG variable "
+                )
+
+        cmd = " ".join(
+            [set_env, sys.executable, "-m", "distributed.cli.dask_scheduler",]
+            + cli_keywords(self.kwargs, cls=_Scheduler)
         )
+        self.proc = await self.connection.create_process(cmd)
 
         # We watch stderr in order to get the address, then we return
         while True:


Test patch: