Import in a separate thread

Peter Hansen peter at engcorp.com
Sat Feb 25 09:07:48 EST 2006


Paul Rubin wrote:
> Peter Hansen <peter at engcorp.com> writes:
>>Sounds like premature optimization.  Speed "things" up?  What things?
>>How long is it taking now to load the modules you are loading?  Even
>>the wxPython demo takes only a few seconds to load on a decent
>>machine, and that's loading a *heck* of a lot of stuff.  
> 
> I know that whenever I start IDLE and it's not already cached, it
> takes a significant amount of time, and that doesn't even use
> wxPython.

I don't dispute that there are in the world programs that take too long 
to start by even objective measures.  I don't dispute that you, Paul, 
might consider IDLE to take too long to start.  I don't think I was 
responding to you, however, but to the OP, who hasn't described anything 
about his situation except that he believes importing modules in a 
separate thread might "speed things up".  To me, that sounded like the 
words of someone who not only might not be aware of the excellent advice 
regarding premature optimization, but who might also not suffer from a 
significant startup delay but who simply imagined that perhaps using a 
"trick" to import things differently might make something run faster. 
Understanding why he wants to do this is important to knowing what the 
best approach is, whether it's to say "don't do it" or to point to 
alternatives (such as a splash screen) which others have found to solve 
the problem.

Just because it appears some people prematurely cry "premature 
optimization" doesn't mean that it's an invalid thing to ask a poster to 
consider.

-Peter




More information about the Python-list mailing list