[mod_python] mod_python executing old versions of my code

Jim Gallacher jpg at jgassociates.ca
Thu Jan 26 20:08:32 EST 2006


Peter Sanchez wrote:
> On Jan 26, 2006, at 4:36 PM, Jim Gallacher wrote:
> 
>> Peter Sanchez wrote:
>>
>>> I have been a little slow on this thread. This is something I had   
>>> planned on emailing the list about myself.
>>> I have a page hosted using mod_python.publisher (mod_python  version  
>>> 3.2.5b) The page returns results from a PSP formatted  template  
>>> system. On a lot of pages I use a variable named "info_msg"
>>> Say I login to an account, info_msg is set to 'You have logged  in.'  
>>> Go to a new page, info_msg isn't used, but the template page  does  
>>> reference it (in case it was used) and you see 'You have  logged in' 
>>> I  have been trying to figure it out, but no such luck.  I just 
>>> found  this thread :)
>>
>>
>> From what you are describing here I don't think this is a module  
>> reload problem. How are you passing info_msg between your requests?  
>> In the apache preform-mpm and worker-mpm models there will be a  
>> python interpreter for each apache child process. Each interpeter  
>> gets it's own copy of the module data. The value for a module  
>> variable set in a request in one child will only be visible to  
>> subsequent requests handled by that same child. If you want to  share 
>> some data between different requests you'll need to use  sessions, 
>> cookies, dump it into a database, or some other  persistent store.
> 
> 
> OK, here is the layout.
> 
> acvars.py contains a dictionary named "ns" that is used for PSP  
> template page data. The ns dictionary contains an entry for  'info_msg' 
> ( ns = {'info_msg':  ' '} )
> 
> Now, index.py has
> 
> from acvars import *
> 
> When a function has completed, and warrants some sort of user update,  
> the index.py function will do:
> 
> ns['info_msg'] = 'Some updating message for the users benefit'
> 
> ns is then passed to the PSP engine to format the HTML and the result  
> is printed to the user.
> 
> This is the same thing for all functions in the index.py script  (which 
> is the front end)
> 
> Should I not be using from ... import * ?

It's not so much that you shouldn't use import, it's just that each 
intepreter will get it's own copy of of your ns dictionary. You have to 
get into a different mindset when working with the apache prefork. 
Pretend that each apache child is a completely independent application 
and you'll get some insight into what's going on. The way you are doing 
things will work in threaded-mpm but it's a non-starter for prefork or 
worker. It's also a useful for pulling static data, such as 
configuration data, into you application.

The problems with old versions of code seeming to persist are related to 
changes to apache modules on disk, which is a different issue to what 
you are seeing.

Jim


More information about the Mod_python mailing list