[mod_python] Module importing with mod_vampire

Graham Dumpleton grahamd at dscpl.com.au
Wed Jul 12 07:33:34 EDT 2006


On 12/07/2006, at 9:23 PM, Graham Dumpleton 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"

When using Vampire, you shouldn't be listing handler directories in  
sys.path
and if you want to use Vampire "import" hook or vampire.importModule()
then directories targeted by them should also not be in sys.path. Thus,
would nearly always when using Vampire use:

   PythonPath 'sys.path'

This ensures that no extra directories are added to 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()

Where in the calling program is this located? For the Vampire "import"
hook to work, the "import" must be at global scope and executed on  
module
import and must not be contained within a function which is only getting
executed when a specific request arrives.

If this is not done, then standard Python "import" mechanism would be
getting used and thus you would see behaviour as I explained in first
mail for when it is used.

Graham


More information about the Mod_python mailing list