[mod_python] mod_python executing old versions of my code

Peter Sanchez pjs at packet-addiction.org
Thu Jan 26 19:44:32 EST 2006

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 * ?

>> As for the "MaxRequestsPerChild 1" work around. How big of a   
>> performance hit does this give? Seems like it would slow things  
>> down  a bit.
> Wrong. It'll slow it down *alot*. This trick should really only be  
> used on a development machine. Consider the following results for a  
> random bit of mod_python code on my machine.
> Using ab -n 1000 and the following apache config:
> StartServers         5
> MinSpareServers      5
> MaxSpareServers      10
> MaxClients          50
> For MaxRequestsPerChild 0
> -------------------------
> Concurrency Level:      1
> Time taken for tests:   4.593905 seconds
> Complete requests:      1000
> Requests per second:    217.68 [#/sec] (mean)
> Time per request:       4.594 [ms] (mean)
> Transfer rate:          1061.84 [Kbytes/sec] received
> For MaxRequestsPerChild 1
> -------------------------
> Concurrency Level:      1
> Time taken for tests:   378.930349 seconds
> Complete requests:      1000
> Requests per second:    2.64 [#/sec] (mean)
> Time per request:       378.930 [ms] (mean)
> Transfer rate:          12.87 [Kbytes/sec] received
> Ouch. Performance drops by a factor of 100 for MaxRequestsPerChild  
> == 1. You could set StartServers to compensate, but it's not a  
> general solution.

I figured it would be horrible to performance. I guess I was under  
stating ;)

>> When will 3.2.6 be available?
> Unofficially, now. ;) Officially... well, we are likely going to  
> have that discussion on the python-dev list in the next day or so.
> Jim



More information about the Mod_python mailing list