This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author brett.cannon
Recipients Arfrever, barry, brett.cannon, durin42, eric.smith, eric.snow, jwilk, sbt, twouters
Date 2014-03-27.14:17:10
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1395929830.6.0.097293725823.issue17621@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2014-03-27 14:17:10brett.cannonsetrecipients: + brett.cannon, twouters, barry, eric.smith, jwilk, durin42, Arfrever, sbt, eric.snow
2014-03-27 14:17:10brett.cannonsetmessageid: <1395929830.6.0.097293725823.issue17621@psf.upfronthosting.co.za>
2014-03-27 14:17:10brett.cannonlinkissue17621 messages
2014-03-27 14:17:10brett.cannoncreate