[Python-Dev] Python startup optimization: script vs. service

Serhiy Storchaka storchaka at gmail.com
Mon Oct 2 11:38:42 EDT 2017

02.10.17 16:26, Victor Stinner пише:
> While "import module" is fast, maybe we should use sometimes a global
> variable to cache the import.
> module = None
> def func():
>     global module
>     if module is None: import module
>     ...

I optimized "import module", and I think it can be optimized even more, 
up to making the above trick unnecessary. Currently there is an overhead 
of checking that the module found in sys.modules is not imported right now.

More information about the Python-Dev mailing list