mod_python use seperated process for python Interpreter. here is a test source to show:
from mod_python import apache
import os
gv=[]
cnt=0
def handler(req):
global gv
global cnt
req.content_type = "text/html"
sb=[]
sb.append("pid %d, interpreter '%s'" % (os.getpid(), req.interpreter))
gv.append("cnt:%d"%(cnt))
cnt+=1
for x in gv:
sb.append(x)
req.write("<br>".join(sb))
return apache.OKwhen the pid is not changed, global value gv is "global", but if pid changed, another context is created. and apache seems to create multi process for mod_python. In fact if there is not a multi-thread implementation in python Interpreter (and for apache2) which i have not confirmed, force a single-thread will make multi request trouble which can be imaged. and this is a existing topic on python thread, thread-safe which i should google study.
and how Django implements global like session, i seek the doc and found almost 3 ways: 1, use a database,
2, use a file, 3, use a third-part memory cache. so all the ways implies mod_python is lack of a good implemented native global solution.
and there seem to be “limitations and consequences” in python multi-thread.
没有评论:
发表评论