module import performance question

Jeff Sykes jeff at cowz.com
Tue Nov 11 07:10:59 CET 2003


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? Any code
optimizations or recommendations? I would like to keep the
architecture the same, just standard cgi scripts, so mod_python looks
like it's a bit more involved than I would like.

Here is a code snip:

dyn_blocks = {}  # set up a dict of the dynamic imports
if confok:  # was the configuration present?
  blocks = getBlocks(config)  # get the application info from config
  for block in blocks:  # each block indictates the ap & pg (module)
    ap = string.split(string.strip(block[1:len(block)]))[0]
    pg = string.split(string.strip(block[1:len(block)]))[1]
    sys.path.append(getAppPath(ap))  # add module dir to sys.path
    if (block[0] == '~'):
      try:
        dyn_blocks[ap + "_" + pg] = __import__(pg)
      except:
        Log.stacktrace(Log.ERROR) # log problem importing module

Any help is appreciated.




More information about the Python-list mailing list