module import performance question

Emile van Sebille emile at fenx.com
Tue Nov 11 10:25:14 EST 2003


"Jeff Sykes" <jeff at cowz.com> wrote in message
news:729b56c7.0311102210.4869d4f6 at posting.google.com...
> I have a cgi script that imports modules based on a user config
file.
> I am suffering some performance problems when I import these
modules.
> Some logging revealed that it seems to be taking about 1.3 seconds
to
> import these modules. This is running on a Windows 2000 box with a
> Pentium II 400 processor, Python 2.1, Apache 1.3.19 as the web
server.
> I don't need screaming performance numbers, but this time is
> excessive. Is it me, or does that number seem kind of slow?

How many modules are being imported?

> Any code
> optimizations or recommendations?

Don't append to sys.path.  Try sys.path.insert(0,addlpath).  Then the
import will get an immediate hit and always the right module rather
than stepping through all the preceeding directories.

HTH,


Emile van Sebille
emile at fenx.com






More information about the Python-list mailing list