Repository: conda/conda

Issue:
`conda search` with Python 3.9 broken on Linux
## Current Behavior

Running `conda search ${pkg}` using Python 3.9 triggers the following exception:
```
# >>>>>>>>>>>>>>>>>>>>>> ERROR REPORT <<<<<<<<<<<<<<<<<<<<<<

    Traceback (most recent call last):
      File "$HOME/.miniconda3-x86_64/lib/python3.9/site-packages/conda/gateways/connection/session.py", line 60, in __call__
        return cls._thread_local.session
    AttributeError: '_thread._local' object has no attribute 'session'
....
    During handling of the above exception, another exception occurred:
....
    Traceback (most recent call last):
      File "$HOME/.miniconda3-x86_64/lib/python3.9/site-packages/conda/exceptions.py", line 1079, in __call__
        return func(*args, **kwargs)
      File "$HOME/.miniconda3-x86_64/lib/python3.9/site-packages/conda/cli/main.py", line 84, in _main
        exit_code = do_call(args, p)
      File "$HOME/.miniconda3-x86_64/lib/python3.9/site-packages/conda/cli/conda_argparse.py", line 83, in do_call
        return getattr(module, func_name)(args, parser)
      File "$HOME/.miniconda3-x86_64/lib/python3.9/site-packages/conda/cli/main_search.py", line 73, in execute
        matches = sorted(SubdirData.query_all(spec, channel_urls, subdirs),
      File "$HOME/.miniconda3-x86_64/lib/python3.9/site-packages/conda/core/subdir_data.py", line 120, in query_all
        result = tuple(concat(executor.map(subdir_query, channel_urls)))
      File "$HOME/.miniconda3-x86_64/lib/python3.9/concurrent/futures/_base.py", line 600, in result_iterator
        yield fs.pop().result()
      File "$HOME/.miniconda3-x86_64/lib/python3.9/concurrent/futures/_base.py", line 433, in result
        return self.__get_result()
      File "$HOME/.miniconda3-x86_64/lib/python3.9/concurrent/futures/_base.py", line 389, in __get_result
        raise self._exception
      File "$HOME/.miniconda3-x86_64/lib/python3.9/concurrent/futures/thread.py", line 52, in run
        result = self.fn(*self.args, **self.kwargs)
      File "$HOME/.miniconda3-x86_64/lib/python3.9/site-packages/conda/core/subdir_data.py", line 112, in <lambda>
        subdir_query = lambda url: tuple(SubdirData(Channel(url), repodata_fn=repodata_fn).query(
      File "$HOME/.miniconda3-x86_64/lib/python3.9/site-packages/conda/core/subdir_data.py", line 125, in query
        self.load()
      File "$HOME/.miniconda3-x86_64/lib/python3.9/site-packages/conda/core/subdir_data.py", line 189, in load
        _internal_state = self._load()
      File "$HOME/.miniconda3-x86_64/lib/python3.9/site-packages/conda/core/subdir_data.py", line 259, in _load
        raw_repodata_str = fetch_repodata_remote_request(
      File "$HOME/.miniconda3-x86_64/lib/python3.9/site-packages/conda/core/subdir_data.py", line 485, in fetch_repodata_remote_request
        session = CondaSession()
      File "$HOME/.miniconda3-x86_64/lib/python3.9/site-packages/conda/gateways/connection/session.py", line 62, in __call__
        session = cls._thread_local.session = super(CondaSessionType, cls).__call__()
      File "$HOME/.miniconda3-x86_64/lib/python3.9/site-packages/conda/gateways/connection/session.py", line 97, in __init__
        self.headers['User-Agent'] = context.user_agent
      File "$HOME/.miniconda3-x86_64/lib/python3.9/site-packages/conda/_vendor/auxlib/decorators.py", line 268, in new_fget
        cache[inner_attname] = func(self)
      File "$HOME/.miniconda3-x86_64/lib/python3.9/site-packages/conda/base/context.py", line 744, in user_agent
        builder.append("%s/%s" % self.os_distribution_name_version)
      File "$HOME/.miniconda3-x86_64/lib/python3.9/site-packages/conda/_vendor/auxlib/decorators.py", line 268, in new_fget
        cache[inner_attname] = func(self)
      File "$HOME/.miniconda3-x86_64/lib/python3.9/site-packages/conda/base/context.py", line 786, in os_distribution_name_version
        from .._vendor.distro import id, version
    ImportError: cannot import name 'id' from partially initialized module 'conda._vendor.distro' (most likely due to a circular import) ($HOME/.miniconda3-x86_64/lib/python3.9/site-packages/conda/_vendor/distro.py)
```

This seems to be Linux specific, as the same command on macOS and Windows 10 works correctly. It also seems to be Py3.9-specific, as switching to Py3.7 or Py3.8 in the base environment resolves the issue.

### Steps to Reproduce

1. Install conda 4.9.2 in a Python 3.9 base environment.
2. Run `conda search python=3.8`.


## Expected Behavior

`conda search` returns a list of matching packages in the configured channels.


## Environment Information

<details open><summary><code>`conda info`</code></summary><p>

```
     active environment : base
    active env location : $HOME/.miniconda3-x86_64
            shell level : 1
       user config file : $HOME/.condarc
 populated config files : 
          conda version : 4.9.2
    conda-build version : 3.21.4
         python version : 3.9.1.final.0
       virtual packages : __cuda=11.0=0
                          __glibc=2.27=0
                          __unix=0=0
                          __archspec=1=x86_64
       base environment : $HOME/.miniconda3-x86_64  (writable)
           channel URLs : https://repo.anaconda.com/pkgs/main/linux-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/linux-64
                          https://repo.anaconda.com/pkgs/r/noarch
          package cache : $HOME/.miniconda3-x86_64/pkgs
                          $HOME/.conda/pkgs
       envs directories : $HOME/.miniconda3-x86_64/envs
                          $HOME/.conda/envs
               platform : linux-64
             user-agent : conda/4.9.2 requests/2.25.1 CPython/3.9.1 Linux/5.4.0-65-generic ubuntu/18.04.5 glibc/2.27
                UID:GID : 1000:100
             netrc file : $HOME/.netrc
           offline mode : False

```
</p></details>


<details open><summary><code>`conda config --show-sources`</code></summary><p>

```
```
</p></details>


<details><summary><code>`conda list --show-channel-urls`</code></summary><p>

```
# packages in environment at $HOME/.miniconda3-x86_64:
#
# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                        main    defaults
anaconda-client           1.7.2            py39h06a4308_0    defaults
attrs                     20.3.0             pyhd3eb1b0_0    defaults
backports                 1.0                pyhd3eb1b0_2    defaults
backports.functools_lru_cache 1.6.1              pyhd3eb1b0_0    defaults
backports.tempfile        1.0                pyhd3eb1b0_1    defaults
backports.weakref         1.0.post1                  py_1    defaults
beautifulsoup4            4.9.3              pyha847dfd_0    defaults
brotlipy                  0.7.0           py39h27cfd23_1003    defaults
bzip2                     1.0.8                h7b6447c_0    defaults
ca-certificates           2021.1.19            h06a4308_0    defaults
certifi                   2020.12.5        py39h06a4308_0    defaults
cffi                      1.14.4           py39h261ae71_0    defaults
chardet                   4.0.0           py39h06a4308_1003    defaults
click                     7.1.2              pyhd3eb1b0_0    defaults
clyent                    1.2.2            py39h06a4308_1    defaults
conda                     4.9.2            py39h06a4308_0    defaults
conda-build               3.21.4           py39h06a4308_0    defaults
conda-package-handling    1.7.2            py39h27cfd23_1    defaults
conda-verify              3.4.2                      py_1    defaults
cryptography              3.3.1            py39h3c74f83_0    defaults
filelock                  3.0.12             pyhd3eb1b0_1    defaults
future                    0.18.2           py39h06a4308_1    defaults
glob2                     0.7                pyhd3eb1b0_0    defaults
icu                       58.2                 he6710b0_3    defaults
idna                      2.10               pyhd3eb1b0_0    defaults
importlib-metadata        2.0.0                      py_1    defaults
importlib_metadata        2.0.0                         1    defaults
iniconfig                 1.1.1              pyhd3eb1b0_0    defaults
ipython_genutils          0.2.0              pyhd3eb1b0_1    defaults
jinja2                    2.11.2             pyhd3eb1b0_0    defaults
jsonschema                3.2.0                      py_2    defaults
jupyter_core              4.7.0            py39h06a4308_0    defaults
ld_impl_linux-64          2.33.1               h53a641e_7    defaults
libarchive                3.4.2                h62408e4_0    defaults
libedit                   3.1.20191231         h14c3975_1    defaults
libffi                    3.3                  he6710b0_2    defaults
libgcc-ng                 9.1.0                hdf63c60_0    defaults
liblief                   0.10.1               h2531618_1    defaults
libstdcxx-ng              9.1.0                hdf63c60_0    defaults
libxml2                   2.9.10               hb55368b_3    defaults
lz4-c                     1.9.3                h2531618_0    defaults
markupsafe                1.1.1            py39h27cfd23_0    defaults
more-itertools            8.6.0              pyhd3eb1b0_0    defaults
nbformat                  5.1.2              pyhd3eb1b0_1    defaults
ncurses                   6.2                  he6710b0_1    defaults
openssl                   1.1.1i               h27cfd23_0    defaults
packaging                 20.8               pyhd3eb1b0_0    defaults
patchelf                  0.12                 h2531618_1    defaults
pip                       20.3.3           py39h06a4308_0    defaults
pkginfo                   1.7.0            py39h06a4308_0    defaults
pluggy                    0.12.0                     py_0    defaults
psutil                    5.7.2            py39h27cfd23_0    defaults
py                        1.10.0             pyhd3eb1b0_0    defaults
py-lief                   0.10.1           py39h2531618_1    defaults
pycosat                   0.6.3            py39h27cfd23_0    defaults
pycparser                 2.20                       py_2    defaults
pyopenssl                 20.0.1             pyhd3eb1b0_1    defaults
pyparsing                 2.4.7              pyhd3eb1b0_0    defaults
pyrsistent                0.17.3           py39h27cfd23_0    defaults
pysocks                   1.7.1            py39h06a4308_0    defaults
pytest                    6.2.2            py39h06a4308_2    defaults
python                    3.9.1                hdb3f193_2    defaults
python-dateutil           2.8.1                      py_0    defaults
python-libarchive-c       2.9                pyhd3eb1b0_0    defaults
pytz                      2020.5             pyhd3eb1b0_0    defaults
pyyaml                    5.4.1            py39h27cfd23_1    defaults
readline                  8.0                  h7b6447c_0    defaults
requests                  2.25.1             pyhd3eb1b0_0    defaults
ripgrep                   12.1.1                        0    defaults
ruamel_yaml               0.15.80          py39h27cfd23_0    defaults
setuptools                52.0.0           py39h06a4308_0    defaults
six                       1.15.0           py39h06a4308_0    defaults
soupsieve                 2.1                pyhd3eb1b0_0    defaults
sqlite                    3.33.0               h62c20be_0    defaults
tk                        8.6.10               hbc83047_0    defaults
toml                      0.10.1                     py_0    defaults
tqdm                      4.55.1             pyhd3eb1b0_0    defaults
traitlets                 5.0.5                      py_0    defaults
tzdata                    2020f                h52ac0ba_0    defaults
urllib3                   1.26.2             pyhd3eb1b0_0    defaults
wheel                     0.36.2             pyhd3eb1b0_0    defaults
xz                        5.2.5                h7b6447c_0    defaults
yaml                      0.2.5                h7b6447c_0    defaults
zipp                      3.4.0              pyhd3eb1b0_0    defaults
zlib                      1.2.11               h7b6447c_3    defaults
zstd                      1.4.5                h9ceee32_0    defaults
```
</p></details>



Discussion:
Just hit this myself. Glad to see you've got it here!
I also encounter this exact problem with the exact same error message, but only sporadically. Sometimes it does not work but when I run it again it often works.

```
% conda info

     active environment : base
    active env location : $HOME/usr/local/opt/mambaforge
            shell level : 1 
       user config file : $HOME/.condarc
 populated config files : $HOME/usr/local/opt/mambaforge/.condarc
                          $HOME/.condarc
          conda version : 4.9.2
    conda-build version : not installed
         python version : 3.9.1.final.0
       virtual packages : __glibc=2.28=0
                          __unix=0=0
                          __archspec=1=x86_64
       base environment : $HOME/usr/local/opt/mambaforge  (writable)
           channel URLs : https://conda.anaconda.org/conda-forge/linux-64
                          https://conda.anaconda.org/conda-forge/noarch
                          https://repo.anaconda.com/pkgs/main/linux-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/linux-64
                          https://repo.anaconda.com/pkgs/r/noarch
          package cache : $HOME/usr/local/opt/mambaforge/pkgs
                          $HOME/.conda/pkgs
       envs directories : $HOME/usr/local/opt/mambaforge/envs
                          $HOME/.conda/envs
               platform : linux-64
             user-agent : conda/4.9.2 requests/2.25.1 CPython/3.9.1 Linux/4.19.0-14-amd64 debian/10 glibc/2.28
                UID:GID : 203887:10516
             netrc file : $HOME/.netrc
           offline mode : False
```
Setting the `repodata_threads` condarc option to 1 seems to be a (non-ideal) workaround.

Resolving patch:
diff --git a/conda/base/context.py b/conda/base/context.py
--- a/conda/base/context.py
+++ b/conda/base/context.py
@@ -783,7 +783,7 @@ def os_distribution_name_version(self):
         #   'Windows', '10.0.17134'
         platform_name = self.platform_system_release[0]
         if platform_name == 'Linux':
-            from .._vendor.distro import id, version
+            from conda._vendor.distro import id, version
             try:
                 distinfo = id(), version(best=True)
             except Exception as e:


Test patch: