diff options
author | Daniel <daniel@tohka.us> | 2022-01-07 22:26:00 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-07 22:26:00 (GMT) |
commit | c9dc1f491e8edb0bc433cde73190a3015d226891 (patch) | |
tree | b71ad3f4d903657f36301e5213bde43b348e0280 /Modules/getpath.py | |
parent | 74d1663580d1914bd110c3ab7282451f5e2cd2b5 (diff) | |
download | cpython-c9dc1f491e8edb0bc433cde73190a3015d226891.zip cpython-c9dc1f491e8edb0bc433cde73190a3015d226891.tar.gz cpython-c9dc1f491e8edb0bc433cde73190a3015d226891.tar.bz2 |
bpo-46297: Fix interpreter crash on startup with multiple PythonPaths set in registry (GH-30466)
Diffstat (limited to 'Modules/getpath.py')
-rw-r--r-- | Modules/getpath.py | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/Modules/getpath.py b/Modules/getpath.py index 37d2ea0..6f2e038 100644 --- a/Modules/getpath.py +++ b/Modules/getpath.py @@ -127,7 +127,7 @@ # checked by looking for the BUILDDIR_TXT file, which contains the # relative path to the platlib dir. The executable_dir value is # derived from joining the VPATH preprocessor variable to the -# directory containing pybuilddir.txt. If it is not found, the +# directory containing pybuilddir.txt. If it is not found, the # BUILD_LANDMARK file is found, which is part of the source tree. # prefix is then found by searching up for a file that should only # exist in the source tree, and the stdlib dir is set to prefix/Lib. @@ -642,19 +642,12 @@ elif not pythonpath: i = 0 while True: try: - keyname = winreg.EnumKey(key, i) - subkey = winreg.OpenKeyEx(key, keyname) - if not subkey: - continue - try: - v = winreg.QueryValue(subkey) - finally: - winreg.CloseKey(subkey) - if isinstance(v, str): - pythonpath.append(v) - i += 1 + v = winreg.QueryValue(key, winreg.EnumKey(key, i)) except OSError: break + if isinstance(v, str): + pythonpath.append(v) + i += 1 finally: winreg.CloseKey(key) except OSError: |