Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions Lib/sysconfig/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ def joinuser(*args):
_CONFIG_VARS = None
# True iff _CONFIG_VARS has been fully initialized.
_CONFIG_VARS_INITIALIZED = False
_config_vars_cached_prefix = None
_config_vars_cached_exec_prefix = None
_USER_BASE = None


Expand Down Expand Up @@ -597,16 +599,20 @@ def get_config_vars(*args):
each argument in the configuration variable dictionary.
"""
global _CONFIG_VARS_INITIALIZED
global _config_vars_cached_prefix
global _config_vars_cached_exec_prefix

# Avoid claiming the lock once initialization is complete.
prefix = os.path.normpath(sys.prefix)
exec_prefix = os.path.normpath(sys.exec_prefix)
if _CONFIG_VARS_INITIALIZED:
# GH-126789: If sys.prefix or sys.exec_prefix were updated, invalidate the cache.
prefix = os.path.normpath(sys.prefix)
exec_prefix = os.path.normpath(sys.exec_prefix)
if _CONFIG_VARS['prefix'] != prefix or _CONFIG_VARS['exec_prefix'] != exec_prefix:
if _config_vars_cached_prefix != prefix or _config_vars_cached_exec_prefix != exec_prefix:
with _CONFIG_VARS_LOCK:
_CONFIG_VARS_INITIALIZED = False
_init_config_vars()
_config_vars_cached_prefix = prefix
_config_vars_cached_exec_prefix = exec_prefix
else:
# Initialize the config_vars cache.
with _CONFIG_VARS_LOCK:
Expand All @@ -616,6 +622,8 @@ def get_config_vars(*args):
# don't re-enter init_config_vars().
if _CONFIG_VARS is None:
_init_config_vars()
_config_vars_cached_prefix = prefix
_config_vars_cached_exec_prefix = exec_prefix

if args:
vals = []
Expand Down
Loading