views:

319

answers:

1

My PyQt application that uses matplotlib takes several seconds to load for the first time, even on a fast machine (the second load time is much shorter as the DLLs are kept in memory by Windows).

I'm wondering whether it's feasible to show a splash screen while the matplotlib library is being loaded. Where does the actual loading take place - is it when the from line is executed? If so, how can I make this line execute during the splash screen and still be able to use the module throughout the code?

A related dilemma is how to test this - can I ask Windows to load the DLLs for every execution and not cache them?

+2  A: 

Yes, loading the module takes place at the line where the import statement is. If you create your QApplication and show your splash screen before that, you should be able to do what you want -- also you need to call QApplication.processEvents() whenever you need the splash screen to update with a new message.

dF
But how can I make the imports visible to top-level code? To make the imports delayed after a splash screen I should execute them inside a method/function - this causes the visibility problem
Eli Bendersky
@eliben: You should have the 1st import of the "heavy" modules inside the function/method. Then the next time they are imported (from the top level of other modules) they are not loaded but just looked up in sys.modules, which is very fast.
dF