MCPcopy Index your code
hub / github.com/python/cpython / exec_module

Method exec_module

Lib/importlib/util.py:256–273  ·  view source on GitHub ↗

Make the module load lazily.

(self, module)

Source from the content-addressed store, hash-verified

254 return self.loader.create_module(spec)
255
256 def exec_module(self, module):
257 """Make the module load lazily."""
258 # Threading is only needed for lazy loading, and importlib.util can
259 # be pulled in at interpreter startup, so defer until needed.
260 import threading
261 module.__spec__.loader = self.loader
262 module.__loader__ = self.loader
263 # Don't need to worry about deep-copying as trying to set an attribute
264 # on an object would have triggered the load,
265 # e.g. ``module.__spec__.loader = None`` would trigger a load from
266 # trying to access module.__spec__.
267 loader_state = {}
268 loader_state['__dict__'] = module.__dict__.copy()
269 loader_state['__class__'] = module.__class__
270 loader_state['lock'] = threading.RLock()
271 loader_state['is_loading'] = False
272 module.__spec__.loader_state = loader_state
273 module.__class__ = _LazyModule
274
275
276__all__ = ['LazyLoader', 'Loader', 'MAGIC_NUMBER',

Callers 4

_import_from_directoryFunction · 0.45
__getattribute__Method · 0.45
import_fileFunction · 0.45

Calls 2

RLockMethod · 0.80
copyMethod · 0.45

Tested by 2

import_fileFunction · 0.36