Message214954
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. |
|
Date |
User |
Action |
Args |
2014-03-27 14:17:10 | brett.cannon | set | recipients:
+ brett.cannon, twouters, barry, eric.smith, jwilk, durin42, Arfrever, sbt, eric.snow |
2014-03-27 14:17:10 | brett.cannon | set | messageid: <1395929830.6.0.097293725823.issue17621@psf.upfronthosting.co.za> |
2014-03-27 14:17:10 | brett.cannon | link | issue17621 messages |
2014-03-27 14:17:10 | brett.cannon | create | |
|