# HG changeset patch
# User Manuel Jacob <me@manueljacob.de>
# Date 1653828259 -7200
#      Sun May 29 14:44:19 2022 +0200
# Branch stable
# Node ID 9dad328434c7b36f55951e98e191d10711ae312c
# Parent  9ea9445c322327a280736383840d4bfb90ae18f6
tests: work around non-thread-safeness of sysconfig.get_config_var()

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -1000,6 +1000,10 @@
     return killmod.killdaemons(pidfile, tryhard=False, remove=True, logfn=vlog)
 
 
+# sysconfig is not thread-safe (https://github.com/python/cpython/issues/92452)
+sysconfiglock = threading.Lock()
+
+
 class Test(unittest.TestCase):
     """Encapsulates a single, runnable test.
 
@@ -1430,7 +1434,8 @@
             env["HGPORT%s" % offset] = '%s' % (self._startport + i)
 
         env = os.environ.copy()
-        env['PYTHONUSERBASE'] = sysconfig.get_config_var('userbase') or ''
+        with sysconfiglock:
+            env['PYTHONUSERBASE'] = sysconfig.get_config_var('userbase') or ''
         env['HGEMITWARNINGS'] = '1'
         env['TESTTMP'] = _bytes2sys(self._testtmp)
         # the FORWARD_SLASH version is useful when running `sh` on non unix