Brett Cannon added the comment:
So as-is, this won't help with startup as we already make sure that no
unnecessary modules are loaded during startup. But one way we do that is
through local imports in key modules, e.g. os.get_exec_path(). So what we could
consider is instead of doing a local import we use lazy imports. We could
introduce importlib._lazy_import() which could be (roughly):
def _lazy_import(fullname):
try:
return sys.modules[fullname]
except KeyError:
spec = find_spec(fullname)
loader = LazyLoader(spec.loader)
# Make module with proper locking and get it inserted into sys.modules.
loader.exec_module(module)
return module
I don't know if that simplifies things, though, compared to a local import. It
might help once a module is identified as on the critical path of startup since
all global imports in that module could be lazy, but we would still need to
identify those critical modules.
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue17621>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com