[mod_python] how do import work?

Chris Curvey ccurvey at earthlink.net
Thu Sep 16 20:15:19 EDT 2004

I think so, given the information in 

I'm (almost) positive that if you're using the prefork MPM (which uses a 
separate, single-threaded process for each request), each OS process 
will have it's own context (see http://httpd.apache.org/docs-2.0/mpm.html).

I have also learned that objects in a context stay alive between 
requests, so something like this (using mpservlets)

class myhandler(HTMLPage):
    def  __init__(self):
        self.messages = []

    def add_message(self):
         self.messages.append("a new message")

will cause self.messages to grow and grow and grow as multiple requests 
hit add_message.  And of course, you can't ever count on the same OS 
process serving the same client over and over.  (This makes sense to me, 
because one of the features of mod_python is that classes get pulled 
into memory once and then don't need to be re-used. )

Of course, there's a possibility that I'm totally off base here, so any 
corrections would be appreciated.

Craig Warren wrote:

>I have read the documentation, but I have not found any place that says
>how imports work.  I have written a previous email about this, but if I
>have a handler that imports another file, does that imported file get
>imported for every thread?  I can print out the interpreter name and it
>is using the same interpreter, but every thread seems to have it's own
>context.  Is this the way it is supposed to work?
>Craig Warren

More information about the Mod_python mailing list