Repository: dask/distributed

Issue:
ValueError: unknown locale: UTF-8
Since #2627 has been merged I'm now getting `unknown locale: UTF-8` when I try and connect to a local scheduler.

```console
$ dask-scheduler
```

```python
from distributed import Client
client = Client('localhost:8786')
client
```

```python-traceback
ValueError: unknown locale: UTF-8
```

<details>
<summary>Full Traceback</summary>

```python-traceback
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-2-a1a08130e5a7> in <module>
----> 1 client = Client('localhost:8786')
      2 client

~/Projects/dask/distributed/distributed/client.py in __init__(self, address, loop, timeout, set_as_default, scheduler_file, security, asynchronous, name, heartbeat_interval, serializers, deserializers, extensions, direct_to_workers, **kwargs)
    725             ext(self)
    726 
--> 727         self.start(timeout=timeout)
    728         Client._instances.add(self)
    729 

~/Projects/dask/distributed/distributed/client.py in start(self, **kwargs)
    890             self._started = asyncio.ensure_future(self._start(**kwargs))
    891         else:
--> 892             sync(self.loop, self._start, **kwargs)
    893 
    894     def __await__(self):

~/Projects/dask/distributed/distributed/utils.py in sync(loop, func, callback_timeout, *args, **kwargs)
    343     if error[0]:
    344         typ, exc, tb = error[0]
--> 345         raise exc.with_traceback(tb)
    346     else:
    347         return result[0]

~/Projects/dask/distributed/distributed/utils.py in f()
    327             if callback_timeout is not None:
    328                 future = gen.with_timeout(timedelta(seconds=callback_timeout), future)
--> 329             result[0] = yield future
    330         except Exception as exc:
    331             error[0] = sys.exc_info()

~/miniconda3/envs/dask/lib/python3.7/site-packages/tornado/gen.py in run(self)
    733 
    734                     try:
--> 735                         value = future.result()
    736                     except Exception:
    737                         exc_info = sys.exc_info()

~/Projects/dask/distributed/distributed/client.py in _start(self, timeout, **kwargs)
    983 
    984         try:
--> 985             await self._ensure_connected(timeout=timeout)
    986         except OSError:
    987             await self._close()

~/Projects/dask/distributed/distributed/client.py in _ensure_connected(self, timeout)
   1054                     "client": self.id,
   1055                     "reply": False,
-> 1056                     "versions": version_module.get_versions(),
   1057                 }
   1058             )

~/Projects/dask/distributed/distributed/versions.py in get_versions(packages)
     36 
     37     d = {
---> 38         "host": get_system_info(),
     39         "packages": get_package_info(
     40             required_packages + optional_packages + list(packages)

~/Projects/dask/distributed/distributed/versions.py in get_system_info()
     57         ("LC_ALL", "%s" % os.environ.get("LC_ALL", "None")),
     58         ("LANG", "%s" % os.environ.get("LANG", "None")),
---> 59         ("LOCALE", "%s.%s" % locale.getlocale()),
     60     ]
     61 

~/miniconda3/envs/dask/lib/python3.7/locale.py in getlocale(category)
    585     if category == LC_ALL and ';' in localename:
    586         raise TypeError('category LC_ALL is not supported')
--> 587     return _parse_localename(localename)
    588 
    589 def setlocale(category, locale=None):

~/miniconda3/envs/dask/lib/python3.7/locale.py in _parse_localename(localename)
    493     elif code == 'C':
    494         return None, None
--> 495     raise ValueError('unknown locale: %s' % localename)
    496 
    497 def _build_localename(localetuple):

ValueError: unknown locale: UTF-8
```

</details>


Discussion:
Seems to be a known issue on MacOS/OS X. 

Setting the following environment variables have resolved the issue for me.

```
export LANG=en_GB.UTF-8
export LC_ALL=en_GB.UTF-8
```

(I had actually already set these but [the way I was starting my Python session](https://www.jacobtomlinson.co.uk/posts/2019/how-to-run-jupyter-lab-at-startup-on-macos/) wasn't running the `.bash_profile` file.)
Hrm, this is unfortunate though in that we've exposed our users to this issue.  

Do you have any sense for what in #2627 might have uncovered this?  It would be nice to not require all of our OSX users to add these environment variables.
I tried digging through but I'm not 100% sure what caused it. 

The problem happens when you call `locale.getlocale()` in Python on any Mac system. The defaults are not a valid locale.

I would guess that maybe `distributed.versions.get_system_info` is being called when it previously wasn't?
Maybe we just remove that line from the system info?  I'm not sure that it provides significant value to anyone in practice.  I would rather that they complain than that all OSX users complain.
That sounds reasonable!

Resolving patch:
diff --git a/distributed/versions.py b/distributed/versions.py
--- a/distributed/versions.py
+++ b/distributed/versions.py
@@ -7,7 +7,6 @@
 import struct
 import os
 import sys
-import locale
 import importlib
 
 
@@ -56,7 +55,6 @@ def get_system_info():
         ("byteorder", "%s" % sys.byteorder),
         ("LC_ALL", "%s" % os.environ.get("LC_ALL", "None")),
         ("LANG", "%s" % os.environ.get("LANG", "None")),
-        ("LOCALE", "%s.%s" % locale.getlocale()),
     ]
 
     return host


Test patch: