Repository: dask/distributed

Issue:
Client HTML repr broken with SpecClusters
From within a Jupyter Notebook.

```python
from dask.distributed import Client
from distributed.deploy.ssh2 import SSHCluster
cluster = SSHCluster(['localhost']*2, connect_kwargs={"known_hosts": None})
client = Client(cluster)
client
```

```python-traceback
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
~/miniconda3/envs/dask/lib/python3.7/site-packages/IPython/core/formatters.py in __call__(self, obj)
    343             method = get_real_method(obj, self.print_method)
    344             if method is not None:
--> 345                 return method()
    346             return None
    347         else:

~/Projects/dask/distributed/distributed/client.py in _repr_html_(self)
    792             and self.cluster.scheduler
    793         ):
--> 794             info = self.cluster.scheduler.identity()
    795             scheduler = self.cluster.scheduler
    796         elif (

AttributeError: 'Scheduler' object has no attribute 'identity'
```


Discussion:
Yeah, I can clean this up if you like.

On Fri, Sep 27, 2019 at 9:27 AM Jacob Tomlinson <notifications@github.com>
wrote:

> From within a Jupyter Notebook.
>
> from dask.distributed import Clientfrom distributed.deploy.ssh2 import SSHCluster
> cluster = SSHCluster(['localhost']*2, connect_kwargs={"known_hosts": None})
> client = Client(cluster)
> client
>
> ---------------------------------------------------------------------------
> AttributeError                            Traceback (most recent call last)
> ~/miniconda3/envs/dask/lib/python3.7/site-packages/IPython/core/formatters.py in __call__(self, obj)
>     343             method = get_real_method(obj, self.print_method)
>     344             if method is not None:
> --> 345                 return method()
>     346             return None
>     347         else:
>
> ~/Projects/dask/distributed/distributed/client.py in _repr_html_(self)
>     792             and self.cluster.scheduler
>     793         ):
> --> 794             info = self.cluster.scheduler.identity()
>     795             scheduler = self.cluster.scheduler
>     796         elif (
> AttributeError: 'Scheduler' object has no attribute 'identity'
>
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/dask/distributed/issues/3098?email_source=notifications&email_token=AACKZTDMAGSJJW4ZZDDTWXTQLYJ3HA5CNFSM4I3HDIM2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HOFN3RQ>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AACKZTAV7JL26LLST4H6VTDQLYJ3HANCNFSM4I3HDIMQ>
> .
>

Sure! I've thrown in #3099 which addresses this exact issue, but there may be more to clean up elsewhere.

Resolving patch:
diff --git a/distributed/client.py b/distributed/client.py
--- a/distributed/client.py
+++ b/distributed/client.py
@@ -786,10 +786,12 @@ def __repr__(self):
             return "<%s: not connected>" % (self.__class__.__name__,)
 
     def _repr_html_(self):
+        from .scheduler import Scheduler
+
         if (
             self.cluster
             and hasattr(self.cluster, "scheduler")
-            and self.cluster.scheduler
+            and isinstance(self.cluster.scheduler, Scheduler)
         ):
             info = self.cluster.scheduler.identity()
             scheduler = self.cluster.scheduler


Test patch: