From e043046e43d3aa9f73f749f55cbcb3f734050c93 Mon Sep 17 00:00:00 2001 From: ahgamut <41098605+ahgamut@users.noreply.github.com> Date: Sun, 15 May 2022 02:50:18 +0530 Subject: [PATCH] remove locking context managers --- .../python/Lib/importlib/_bootstrap.py | 61 +++++++++---------- third_party/python/Python/import.c | 2 +- 2 files changed, 29 insertions(+), 34 deletions(-) diff --git a/third_party/python/Lib/importlib/_bootstrap.py b/third_party/python/Lib/importlib/_bootstrap.py index 550add75444..ec14d8471a7 100644 --- a/third_party/python/Lib/importlib/_bootstrap.py +++ b/third_party/python/Lib/importlib/_bootstrap.py @@ -531,24 +531,23 @@ def _module_repr_from_spec(spec): def _exec(spec, module): """Execute the spec's specified module in an existing module's namespace.""" name = spec.name - with _ModuleLockManager(name): - if sys.modules.get(name) is not module: - msg = 'module {!r} not in sys.modules'.format(name) - raise ImportError(msg, name=name) - if spec.loader is None: - if spec.submodule_search_locations is None: - raise ImportError('missing loader', name=spec.name) - # namespace package - _init_module_attrs(spec, module, override=True) - return module + if sys.modules.get(name) is not module: + msg = 'module {!r} not in sys.modules'.format(name) + raise ImportError(msg, name=name) + if spec.loader is None: + if spec.submodule_search_locations is None: + raise ImportError('missing loader', name=spec.name) + # namespace package _init_module_attrs(spec, module, override=True) - if not hasattr(spec.loader, 'exec_module'): - # (issue19713) Once BuiltinImporter and ExtensionFileLoader - # have exec_module() implemented, we can add a deprecation - # warning here. - spec.loader.load_module(name) - else: - spec.loader.exec_module(module) + return module + _init_module_attrs(spec, module, override=True) + if not hasattr(spec.loader, 'exec_module'): + # (issue19713) Once BuiltinImporter and ExtensionFileLoader + # have exec_module() implemented, we can add a deprecation + # warning here. + spec.loader.load_module(name) + else: + spec.loader.exec_module(module) return sys.modules[name] @@ -613,8 +612,7 @@ def _load(spec): clobbered. """ - with _ModuleLockManager(spec.name): - return _load_unlocked(spec) + return _load_unlocked(spec) # Loaders ##################################################################### @@ -816,15 +814,14 @@ def _find_spec(name, path, target=None): # sys.modules provides one. is_reload = name in sys.modules for finder in meta_path: - with _ImportLockContext(): - try: - find_spec = finder.find_spec - except AttributeError: - spec = _find_spec_legacy(finder, name, path) - if spec is None: - continue - else: - spec = find_spec(name, path, target) + try: + find_spec = finder.find_spec + except AttributeError: + spec = _find_spec_legacy(finder, name, path) + if spec is None: + continue + else: + spec = find_spec(name, path, target) if spec is not None: # The parent import may have already imported this module. if not is_reload and name in sys.modules: @@ -911,17 +908,15 @@ def _find_and_load_unlocked(name, import_): def _find_and_load(name, import_): """Find and load the module.""" - with _ModuleLockManager(name): - module = sys.modules.get(name, _NEEDS_LOADING) - if module is _NEEDS_LOADING: - return _find_and_load_unlocked(name, import_) + module = sys.modules.get(name, _NEEDS_LOADING) + if module is _NEEDS_LOADING: + return _find_and_load_unlocked(name, import_) if module is None: message = ('import of {} halted; ' 'None in sys.modules'.format(name)) raise ModuleNotFoundError(message, name=name) - _lock_unlock_module(name) return module diff --git a/third_party/python/Python/import.c b/third_party/python/Python/import.c index 78c01701118..a989f4e36ec 100644 --- a/third_party/python/Python/import.c +++ b/third_party/python/Python/import.c @@ -1613,7 +1613,7 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *globals, Py_DECREF(value); if (initializing == -1) PyErr_Clear(); - if (initializing > 0) { + if (0 && initializing > 0) { value = _PyObject_CallMethodIdObjArgs(interp->importlib, &PyId__lock_unlock_module, abs_name, NULL);