diff options
| author | Chris Markiewicz <effigies@gmail.com> | 2024-03-28 10:59:31 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-28 10:59:31 (GMT) |
| commit | 9a1e55b8c5723206116f7016921be3937ef2f4e5 (patch) | |
| tree | db17127486333cef222b5d2cec226e71115e2503 /Lib/importlib/util.py | |
| parent | 4c71d51a4b7989fc8754ba512c40e21666f9db0d (diff) | |
| download | cpython-9a1e55b8c5723206116f7016921be3937ef2f4e5.zip cpython-9a1e55b8c5723206116f7016921be3937ef2f4e5.tar.gz cpython-9a1e55b8c5723206116f7016921be3937ef2f4e5.tar.bz2 | |
gh-117178: Recover lazy loading of self-referential modules (#117179)
Diffstat (limited to 'Lib/importlib/util.py')
| -rw-r--r-- | Lib/importlib/util.py | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/Lib/importlib/util.py b/Lib/importlib/util.py index da9bd08..f1bb4b1 100644 --- a/Lib/importlib/util.py +++ b/Lib/importlib/util.py @@ -178,12 +178,11 @@ class _LazyModule(types.ModuleType): # Only the first thread to get the lock should trigger the load # and reset the module's class. The rest can now getattr(). if object.__getattribute__(self, '__class__') is _LazyModule: - # The first thread comes here multiple times as it descends the - # call stack. The first time, it sets is_loading and triggers - # exec_module(), which will access module.__dict__, module.__name__, - # and/or module.__spec__, reentering this method. These accesses - # need to be allowed to proceed without triggering the load again. - if loader_state['is_loading'] and attr.startswith('__') and attr.endswith('__'): + # Reentrant calls from the same thread must be allowed to proceed without + # triggering the load again. + # exec_module() and self-referential imports are the primary ways this can + # happen, but in any case we must return something to avoid deadlock. + if loader_state['is_loading']: return object.__getattribute__(self, attr) loader_state['is_loading'] = True |
