Module load times

Steven D'Aprano steve at
Fri Aug 14 04:10:20 CEST 2015

On Fri, 14 Aug 2015 07:12 am, Joseph L. Casale wrote:

>> What makes you think the import might be a problem? That's a one-time
>> thing. Or is your application a command-line tool or so that needs to
>> start and terminate quickly?
> The code is used within plugin points and soon to be asynchronous code
> (once  the original broken implementation is fixed) where in some cases it
> will be instantiated 100's of 1000's of times etc...

Importing is not the same as instantiation.

When you import a module, the code is only read from disk and instantiated
the first time. Then it is cached. Subsequent imports in the same Python
session use the cached version.

So the answer will depend on your application. If your application runs for
a long time (relatively speaking), and imports the plugins 100s or 1000s of
times, it should not matter. Only the first import is likely to be slow.

But if the application starts up, imports the plugin, then shuts down, then
repeats 100s or 1000s of times, that may be slow. Or if it launches
separate processes, each of which imports the plugin.

Without understanding your application, and the plugin model, it is
difficult to predict the impact of importing.


More information about the Python-list mailing list