@@ -182,6 +182,8 @@ def joinuser(*args):
182182_CONFIG_VARS = None
183183# True iff _CONFIG_VARS has been fully initialized.
184184_CONFIG_VARS_INITIALIZED = False
185+ _config_vars_cached_prefix = None
186+ _config_vars_cached_exec_prefix = None
185187_USER_BASE = None
186188
187189
@@ -600,16 +602,20 @@ def get_config_vars(*args):
600602 each argument in the configuration variable dictionary.
601603 """
602604 global _CONFIG_VARS_INITIALIZED
605+ global _config_vars_cached_prefix
606+ global _config_vars_cached_exec_prefix
603607
604608 # Avoid claiming the lock once initialization is complete.
609+ prefix = os .path .normpath (sys .prefix )
610+ exec_prefix = os .path .normpath (sys .exec_prefix )
605611 if _CONFIG_VARS_INITIALIZED :
606612 # GH-126789: If sys.prefix or sys.exec_prefix were updated, invalidate the cache.
607- prefix = os .path .normpath (sys .prefix )
608- exec_prefix = os .path .normpath (sys .exec_prefix )
609- if _CONFIG_VARS ['prefix' ] != prefix or _CONFIG_VARS ['exec_prefix' ] != exec_prefix :
613+ if _config_vars_cached_prefix != prefix or _config_vars_cached_exec_prefix != exec_prefix :
610614 with _CONFIG_VARS_LOCK :
611615 _CONFIG_VARS_INITIALIZED = False
612616 _init_config_vars ()
617+ _config_vars_cached_prefix = prefix
618+ _config_vars_cached_exec_prefix = exec_prefix
613619 else :
614620 # Initialize the config_vars cache.
615621 with _CONFIG_VARS_LOCK :
@@ -619,6 +625,8 @@ def get_config_vars(*args):
619625 # don't re-enter init_config_vars().
620626 if _CONFIG_VARS is None :
621627 _init_config_vars ()
628+ _config_vars_cached_prefix = prefix
629+ _config_vars_cached_exec_prefix = exec_prefix
622630
623631 if args :
624632 vals = []
0 commit comments