Graham Dumpleton
grahamd at dscpl.com.au
Fri Apr 28 09:01:56 EDT 2006
Consider reading: http://www.dscpl.com.au/articles/modpython-004.html This will give you some more background information on what Jim is talking about in respect of MPMs, interpreters models etc. Access to globals in your module code also wasn't thread safe and could not do quite what you expect in a multithread MPM. Graham On 28/04/2006, at 10:58 PM, Jim Gallacher wrote: > yjfuk wrote: >> I think it's my code error,but I am not sure. >> My apapche conf is like this : >> SetHandler mod_python >> PythonHandler mod_python.publisher >> I use psp as my template.I confuse that the variable seems to share >> the values among the pages. >> e.g. a page named index.py contain functions as below: >> test=0 >> def a(req): >> global test >> req.write(str(test)) >> test=test+1 >> def b(req): >> global test >> req.write(str(test)) >> test=test+1 >> when you visit the page http://localhost/index/a it print 0,then >> visit page http://localhost/index/b >> it print 1 as if the variable 'test' is pass vis get or post >> method.why? >> is it the cache trick? > > It's not a trick, it's the way python works. The interpreter created > by mod_python is persistent between requests and you increment the > value of test in your code. > > However you can't depend on the value of test for apache-mpm's such as > forked and worker. You'll have multiple interpreters with these mpm's > and each interpreter will get it's own copy of the data. Which > interpreter will handle a particular request so if you visit > http://localhost/index/a 10 times you might see this seemingly random > pattern: > > 0 > 1 > 0 > 2 > 1 > 3 > 0 > 1 > 4 > 3 > > Unless you fully understand this you should avoid variables defined at > the module level for anything other than constants. > > Jim
|