File tree Expand file tree Collapse file tree 1 file changed +7
-2
lines changed
Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -174,9 +174,14 @@ def __getattribute__(self, attr):
174174 __spec__ = object .__getattribute__ (self , '__spec__' )
175175 loader_state = __spec__ .loader_state
176176 with loader_state ['lock' ]:
177+ # Only the first thread to get the lock should trigger the load
178+ # and reset the module's class. The rest can now getattr().
177179 if object .__getattribute__ (self , '__class__' ) is _LazyModule :
178- # exec_module() will access dunder attributes, so we use a reentrant
179- # lock and an event to prevent infinite recursion.
180+ # The first thread comes here multiple times as it descends the
181+ # call stack. The first time, it sets is_loading and triggers
182+ # exec_module(), which will access module.__dict__, module.__name__,
183+ # and/or module.__spec__, reentering this method. These accesses
184+ # need to be allowed to proceed without triggering the load again.
180185 if loader_state ['is_loading' ].is_set () and attr [:2 ] == attr [- 2 :] == '__' :
181186 return object .__getattribute__ (self , attr )
182187 loader_state ['is_loading' ].set ()
You can’t perform that action at this time.
0 commit comments