[mod_python] how do import work?

Craig Warren craig.warren at encorp.com
Fri Sep 17 10:40:43 EDT 2004


Thanks for the info, this is what I have been experiencing. Each
"thread" has its own context, so if you set a variable in the module, it
will stay alive between requests, but might be different between threads
that serve the requests.  This is fine, I am just trying to understand
how all this works.  

So far I really like how this all works and it seems to work pretty
well.  The only thing I think could use a little rework is when a psp
page includes a file, if you modify the included file the main file
doesn't update with the changes.  You have to modify the main file to
see the changes.  It would be nice if you changed the included file and
the changes be seen in the file that included it.  Not that big of deal,
you just have to write a little script that touches all the file so then
it reloads the main file.

Thanks again,
Craig
   


 On Thu, 2004-09-16 at 17:15, Chris Curvey wrote:
> I think so, given the information in 
> http://modpython.org/FAQ/faqw.py?req=show&file=faq03.001.htp
> 
> 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?
> >
> >Thanks,
> >
> >Craig Warren
> >
> >
> >  
> >
-- 
Craig Warren
Senior Programmer	
Encorp
craig.warren at encorp.com


More information about the Mod_python mailing list