diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py index f7c89ca..3a79e58 100644 --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -929,6 +929,10 @@ _ERR_MSG_PREFIX = 'No module named ' _ERR_MSG = _ERR_MSG_PREFIX + '{!r}' def _find_and_load_unlocked(name, import_): + if name == 'package': + global time + time.sleep(0.010) + path = None parent = name.rpartition('.')[0] if parent: @@ -955,8 +959,15 @@ def _find_and_load_unlocked(name, import_): return module +time = None + + def _find_and_load(name, import_): """Find and load the module.""" + global time + if name == 'package': + import time + _imp.acquire_lock() if name not in sys.modules: with _ModuleLockManager(name): diff --git a/Lib/test/test_import/__init__.py b/Lib/test/test_import/__init__.py index 8424ed7..e6e3be8 100644 --- a/Lib/test/test_import/__init__.py +++ b/Lib/test/test_import/__init__.py @@ -394,7 +394,7 @@ class ImportTests(unittest.TestCase): nonlocal exc exc = e - for i in range(10): + for i in range(1): event = threading.Event() threads = [threading.Thread(target=run) for x in range(2)] try: