Skip to content

Commit fd630e7

Browse files
committed
fix gh-117178: Fall back to object.__getattribute__ for any reentrant lookups
1 parent 367cdc1 commit fd630e7

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

Lib/importlib/util.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,11 @@ def __getattribute__(self, attr):
178178
# Only the first thread to get the lock should trigger the load
179179
# and reset the module's class. The rest can now getattr().
180180
if object.__getattribute__(self, '__class__') is _LazyModule:
181-
# The first thread comes here multiple times as it descends the
182-
# call stack. The first time, it sets is_loading and triggers
183-
# exec_module(), which will access module.__dict__, module.__name__,
184-
# and/or module.__spec__, reentering this method. These accesses
185-
# need to be allowed to proceed without triggering the load again.
186-
if loader_state['is_loading'] and attr.startswith('__') and attr.endswith('__'):
181+
# Reentrant calls from the same thread must be allowed to proceed without
182+
# triggering the load again.
183+
# exec_module() and self-referential imports are the primary ways this can
184+
# happen, but in any case we must return something to avoid deadlock.
185+
if loader_state['is_loading']:
187186
return object.__getattribute__(self, attr)
188187
loader_state['is_loading'] = True
189188

0 commit comments

Comments
 (0)