mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-08-09 19:30:29 +00:00
remove locking context managers
This commit is contained in:
parent
d5543c8f78
commit
e043046e43
2 changed files with 29 additions and 34 deletions
61
third_party/python/Lib/importlib/_bootstrap.py
vendored
61
third_party/python/Lib/importlib/_bootstrap.py
vendored
|
@ -531,24 +531,23 @@ def _module_repr_from_spec(spec):
|
||||||
def _exec(spec, module):
|
def _exec(spec, module):
|
||||||
"""Execute the spec's specified module in an existing module's namespace."""
|
"""Execute the spec's specified module in an existing module's namespace."""
|
||||||
name = spec.name
|
name = spec.name
|
||||||
with _ModuleLockManager(name):
|
if sys.modules.get(name) is not module:
|
||||||
if sys.modules.get(name) is not module:
|
msg = 'module {!r} not in sys.modules'.format(name)
|
||||||
msg = 'module {!r} not in sys.modules'.format(name)
|
raise ImportError(msg, name=name)
|
||||||
raise ImportError(msg, name=name)
|
if spec.loader is None:
|
||||||
if spec.loader is None:
|
if spec.submodule_search_locations is None:
|
||||||
if spec.submodule_search_locations is None:
|
raise ImportError('missing loader', name=spec.name)
|
||||||
raise ImportError('missing loader', name=spec.name)
|
# namespace package
|
||||||
# namespace package
|
|
||||||
_init_module_attrs(spec, module, override=True)
|
|
||||||
return module
|
|
||||||
_init_module_attrs(spec, module, override=True)
|
_init_module_attrs(spec, module, override=True)
|
||||||
if not hasattr(spec.loader, 'exec_module'):
|
return module
|
||||||
# (issue19713) Once BuiltinImporter and ExtensionFileLoader
|
_init_module_attrs(spec, module, override=True)
|
||||||
# have exec_module() implemented, we can add a deprecation
|
if not hasattr(spec.loader, 'exec_module'):
|
||||||
# warning here.
|
# (issue19713) Once BuiltinImporter and ExtensionFileLoader
|
||||||
spec.loader.load_module(name)
|
# have exec_module() implemented, we can add a deprecation
|
||||||
else:
|
# warning here.
|
||||||
spec.loader.exec_module(module)
|
spec.loader.load_module(name)
|
||||||
|
else:
|
||||||
|
spec.loader.exec_module(module)
|
||||||
return sys.modules[name]
|
return sys.modules[name]
|
||||||
|
|
||||||
|
|
||||||
|
@ -613,8 +612,7 @@ def _load(spec):
|
||||||
clobbered.
|
clobbered.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
with _ModuleLockManager(spec.name):
|
return _load_unlocked(spec)
|
||||||
return _load_unlocked(spec)
|
|
||||||
|
|
||||||
|
|
||||||
# Loaders #####################################################################
|
# Loaders #####################################################################
|
||||||
|
@ -816,15 +814,14 @@ def _find_spec(name, path, target=None):
|
||||||
# sys.modules provides one.
|
# sys.modules provides one.
|
||||||
is_reload = name in sys.modules
|
is_reload = name in sys.modules
|
||||||
for finder in meta_path:
|
for finder in meta_path:
|
||||||
with _ImportLockContext():
|
try:
|
||||||
try:
|
find_spec = finder.find_spec
|
||||||
find_spec = finder.find_spec
|
except AttributeError:
|
||||||
except AttributeError:
|
spec = _find_spec_legacy(finder, name, path)
|
||||||
spec = _find_spec_legacy(finder, name, path)
|
if spec is None:
|
||||||
if spec is None:
|
continue
|
||||||
continue
|
else:
|
||||||
else:
|
spec = find_spec(name, path, target)
|
||||||
spec = find_spec(name, path, target)
|
|
||||||
if spec is not None:
|
if spec is not None:
|
||||||
# The parent import may have already imported this module.
|
# The parent import may have already imported this module.
|
||||||
if not is_reload and name in sys.modules:
|
if not is_reload and name in sys.modules:
|
||||||
|
@ -911,17 +908,15 @@ _NEEDS_LOADING = object()
|
||||||
|
|
||||||
def _find_and_load(name, import_):
|
def _find_and_load(name, import_):
|
||||||
"""Find and load the module."""
|
"""Find and load the module."""
|
||||||
with _ModuleLockManager(name):
|
module = sys.modules.get(name, _NEEDS_LOADING)
|
||||||
module = sys.modules.get(name, _NEEDS_LOADING)
|
if module is _NEEDS_LOADING:
|
||||||
if module is _NEEDS_LOADING:
|
return _find_and_load_unlocked(name, import_)
|
||||||
return _find_and_load_unlocked(name, import_)
|
|
||||||
|
|
||||||
if module is None:
|
if module is None:
|
||||||
message = ('import of {} halted; '
|
message = ('import of {} halted; '
|
||||||
'None in sys.modules'.format(name))
|
'None in sys.modules'.format(name))
|
||||||
raise ModuleNotFoundError(message, name=name)
|
raise ModuleNotFoundError(message, name=name)
|
||||||
|
|
||||||
_lock_unlock_module(name)
|
|
||||||
return module
|
return module
|
||||||
|
|
||||||
|
|
||||||
|
|
2
third_party/python/Python/import.c
vendored
2
third_party/python/Python/import.c
vendored
|
@ -1613,7 +1613,7 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *globals,
|
||||||
Py_DECREF(value);
|
Py_DECREF(value);
|
||||||
if (initializing == -1)
|
if (initializing == -1)
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
if (initializing > 0) {
|
if (0 && initializing > 0) {
|
||||||
value = _PyObject_CallMethodIdObjArgs(interp->importlib,
|
value = _PyObject_CallMethodIdObjArgs(interp->importlib,
|
||||||
&PyId__lock_unlock_module, abs_name,
|
&PyId__lock_unlock_module, abs_name,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue