[mod_python] Module importing with mod_vampire

Graham Dumpleton grahamd at dscpl.com.au
Wed Jul 12 07:14:28 EDT 2006


On 12/07/2006, at 6:47 PM, apocalypznow wrote:

> Module importing with mod_vampire is not working.  I get one of  
> several old copies of the python program I am importing!
>
> Here is the relevant section of my httpd.conf file:
> Alias /forums "/var/www/mod_python/forums"
> <Directory /var/www/mod_python/forums>
>   SetHandler python-program
>   PythonHandler vampire
>   PythonDebug On
>   Options -MultiViews -Indexes
>   PythonPath "['/var/www/mod_python/lib','/var/www/mod_python/ 
> forums']+sys.path"
>   PythonOption VampireImportHooks On
> </Directory>
>
> The python program in question "ticket.py" is in the /var/www/ 
> mod_python/lib folder.  I have also moved it to the /var/www/ 
> mod_python/forums folder.  The results are the same no matter where  
> it is.  The calling program is in the /var/www/mod_python/forums  
> folder, and it does this:
>
> import ticket
> d = ticket.getData()

This is nothing to do with Vampire, it is how builtin Python "import"  
behaves
in mod_python. Specifically, when you use "import" the module first  
loaded
is the one that will be used thereafter. The reason you are seeing  
several
old copies is most likely because you are using a version of Apache  
running
with the prefork MPM and each request is being served by a different  
Apache
child process and which has at different times loaded different  
versions of
the module.

If the module the "import" is being done in is the top level handler  
module
loaded by Vampire, instead of using "import" use:

   ticket = vampire.importModule("ticket")

Vampire's module importer does not look in sys.path though, so if the  
"ticket"
module is not in the same directory, you need to specify the path to  
get the
module from.

   ticket = vampire.importModule("ticket", path=["/some/directory"])

Directories which modules are imported from using Vampire module  
loader should
not also be in sys.path as strange things can happen.

BTW, you should also read:

   http://www.dscpl.com.au/articles/modpython-003.html

for general background information on problems with the module  
importer in
mod_python.

Graham


More information about the Mod_python mailing list