[mod_python] Threading and apache.import_module

Graham Dumpleton grahamd at dscpl.com.au
Mon Jun 20 02:25:03 EDT 2005

Nicolas Lehuen wrote ..
> Regarding the naming of the package, don't give a module the same name
> as its filename, that is to say with slashes and dots. It seems that
> this breaks some behaviour of the Python import system, that is to say
> that some imports that are performed in the dynamically loaded module
> misteriously fail. I use a re.sub(r'\W+','_',filename) and everything
> is OK. That being said, I didn't know about name length restrictions
> so I have to correct my code to cope with this issue.

The length restriction is that the name of the module can not be longer than
MAXPATHLEN. Thus, as long as you don't excessively increase the length
of the name when doing substitutions such that that is exceeded, you
should be okay.

BTW, using the simple substitution you have, I think one could probably
construct two pathnames which when substituted would result in the
same thing. I currently use:

    stub = os.path.splitext(file)[0]
    label = md5.new(stub).hexdigest()
    label = self._prefix + label
    label = label + "_" + str(len(stub))

For the length of data we are talking about, I doubt that md5 collisions
are going to occur. I append the length to stir things up a little bit more
but probably don't even need that and MD5 hexdigest is probably good


More information about the Mod_python mailing list