Earlier quoted context omitted.
With the LazyLoader technique I described at https://news.ycombinator.com/item?id=45467489 , there is no problem: >>> import nonexistent_module Traceback (most recent call last): File " ", line 1, in import nonexistent_module File " ", line 1360, in _find_and_load File " ", line 1322, in _find_and_load_unlocked File " ", line 1262, in _find_spec File " ", line 8, in find_spec base.loader = LazyLoader(base.loader) ^^^…
Ahh, so you do the find first, and keep that around before loading. I have bad memories of using a network filesystem where my Python app's startup time was 5 or more seconds because of all the small file lookups for the import were really slow. I fixed it by importing modules in functions, only when needed, so the time went down to less than a second. (It was even better using a zipimport, but for other reasons we d…
(Trying to do "fallback" logic with lazily-loaded modules is also susceptible to race conditions, of course. What if someone defines the module before you try to use it?)