[mod_python] mod_python executing old versions of my code

James Paige jamesp at westcoastaerospace.com
Tue Jan 24 17:51:47 EST 2006

I'm new to mod_python... so maybe I have missed something fundamental 
here, but mod_python seems to be keeping several copies of my old code 
in memory, so when I make changes and reload the page, sometimes I get 
my changes, and sometimes I get a seemingly-random version of the code 
that I have already changed.

Here is a simple test-case I set up.

Here is my .htaccess file:

SetHandler python-program
PythonHandler main
PythonDebug On

(I am using version 2.7.10 as shipped in Debian stable's 
libapache-mod-python package, which is why I am using "python-program")

Here is my main.py

from mod_python import apache
import testmodule

def handler(req):
     req.write("Hello World!")
     return apache.OK

and here is the imported testmodule.py

def foo(req):
    req.write('three blind mice')

The first time I load this test in my web browser, I see the expected 

   Hello World!three blind mice

I edit testmodule.py and change the string to something else:

def foo(req):
    req.write('mary had a little lamb')

I then reload my web browser. Sometimes this results in "Hello 
World!mary had a little lamb", and sometimes it reuslts in "Hello 
World!three blind mice"

I edit the string again, and hit reload again. Maybe I get the new 
string.... or maybe I get one of the strings I used previously. I keep 
making changes to testmodule.py and I keep reloading the results, and 
the results are almost always wrong.

I know this is not a browser cache problem. I have cleared/disabled my 
web-browser's cache.

I read about "Multiple Interpreters" in the documentation, and have 
tried to force my code to run in a single interpreter by adding:

PythonInterpreter "test_interpreter"

to my .htaccess file, but that makes no difference.

This problem only occurs in the included module. I can edit main.py and 
my changes are always applied. I notice in the apache logs that 
everytime I reload the page I see:

   [notice] mod_python: (Re)importing main from None

But I can find no way to force testmodule to be re-imported. What am I 
doing wrong?

James Paige

More information about the Mod_python mailing list