[mod_python] Vampire for module reloading

Graham Dumpleton grahamd at dscpl.com.au
Thu Jul 7 02:47:05 EDT 2005

Gonzalo =?ISO-8859-1?Q?Sainz-Tr=E1paga?= wrote ..
> I would like to know if I can install Vampire on a shared hosting
> computer to which I don't have root access (and probably just FTP
> access),

This is generally possible. You would need to set PythonPath explicitly
within your .htaccess files to reference the parent directory of where
Vampire is installed. You should ensure though that your code runs
in its own interpreter namespace just in case someone else were also
to try and use Vampire. Although, using a distinct interpreter is good
practice when using shared hosting regardless of whether you are
using shared hosting.

> and if it's possible to drop-in Vampire's module reloading
> system instead of mod_python's without major rewrites of my code.

First you need to ask whether it is worth it. Although the standard
module importing system doesn't work as well as it should, unless
your code and the relationship between explicitly imported modules
is complicated, you can probably get away with using what is already
provided with mod_python.

The simplest hack to avoid a restart yet force your files to be reloaded
is simply to touch all your files so that there modification times change.
You just need to ensure that automatic reloading is always enabled.

As someone pointed out already, any local imports of modules which
are a part of your web application should not use the "import" statement
but should instead explicitly use apache.import_module(). Although
they said to replace all uses of "import", you should only do so for your
own code. Do not use apache.import_module() for modules which are
a part of the standard Python distribution. The apache.import_module()
function also doesn't work very well with packages, so avoid using
packages for your own code.

Note that you should also avoid having the same named Python module
file in multiple locations as apache.import_module() doesn't cope with
that very well. Ie., don't have multiple index.py files for example if using

You should also avoid setting PythonPath and supply an explicit directory
location to apache.import_module() all the time. ie.,

  module = apache.import_module(name,path=[directory])

This will help to avoid issues in picking up the wrong module if you use
a name which mirrors a standard module name.

There are lots of other issues to contend with, but really depends on
how complicated your code is. Most people don't have that complicated
a system and so the provided mechanism and its problems can be
lived with.

> If this is possible, I would really appreciate some quick pointers and
> directions on how to accomplish this. Basically, some comments on the
> code snippet that appears under "Module Importing System" on Vampire's
> website would be great.

You are better of using what mod_python provides. When you understand
how module loading works in that and come to understand the problems
in the provided system and how it is affecting you, then you might look at
Vampire again. Even before that, you are probably still better to post here
on the mailing list as to the exact problem you are seeing in case there is
a workaround for it.


More information about the Mod_python mailing list