summaryrefslogtreecommitdiffstats
path: root/Lib/importlib
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2012-08-27 22:24:52 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2012-08-27 22:24:52 (GMT)
commit4f0338cab745c8678df4113f2fcd38dd234a73f8 (patch)
tree9e8d59aa1480b43eb818f2510d2c105500b99960 /Lib/importlib
parent79dbded0fae7c1c10454a391ae3ebbb39c5b7a0f (diff)
downloadcpython-4f0338cab745c8678df4113f2fcd38dd234a73f8.zip
cpython-4f0338cab745c8678df4113f2fcd38dd234a73f8.tar.gz
cpython-4f0338cab745c8678df4113f2fcd38dd234a73f8.tar.bz2
Issue #15781: Fix two small race conditions in import's module locking.
Diffstat (limited to 'Lib/importlib')
-rw-r--r--Lib/importlib/_bootstrap.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
index 171adc5..6697b2b 100644
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -268,8 +268,10 @@ def _get_module_lock(name):
Should only be called with the import lock taken."""
lock = None
- if name in _module_locks:
+ try:
lock = _module_locks[name]()
+ except KeyError:
+ pass
if lock is None:
if _thread is None:
lock = _DummyModuleLock(name)
@@ -543,6 +545,9 @@ def module_for_loader(fxn):
# implicitly imports 'locale' and would otherwise trigger an
# infinite loop.
module = new_module(fullname)
+ # This must be done before putting the module in sys.modules
+ # (otherwise an optimization shortcut in import.c becomes wrong)
+ module.__initializing__ = True
sys.modules[fullname] = module
module.__loader__ = self
try:
@@ -554,8 +559,9 @@ def module_for_loader(fxn):
module.__package__ = fullname
else:
module.__package__ = fullname.rpartition('.')[0]
- try:
+ else:
module.__initializing__ = True
+ try:
# If __package__ was not set above, __import__() will do it later.
return fxn(self, module, *args, **kwargs)
except: