|
Sébastien Arnaud
arnaudsj at mac.com
Mon Jun 6 12:13:50 EDT 2005
Hi,
I have attempted to write my own little framework ("heracles" I named
it;) to develop applications faster using mod_python and it is coming
along great. Mainly I am using the framework to keep handy a bunch of
little utils functions/objects I have written along the years while
working with mod_python, such as a pool of connections for DB
connections, XML/XSLT rendering, Cheetah template rendering, etc...
I am hitting the wall on a very stupid problem that I thought I had
working. I can't get an object declared as global to remain in memory...
Under Apache Pre-fork MPM model, this I understand, but under the MPM
Worker model, where I specify to start 10 threads in one process, I
kind of don't get it... Maybe some of you will be able to spot what I
am doing wrong.
Basically, what I am trying to do is to keep the object mySitePool in
memory since each Site object (heracles.site) has everything needed
by a thread to process a request. At the first request the mySitePool
object should get initialized, but for any other requests it should
be simply the matter of retrieving one Site object via the Queueing
mechanism to process one request. Right now the problem is that I am
able to see for each request one entry in the apache log file that
the mySitePool is being initialized...
Thank you in advance for any pointers or solutions you may have!
Apache2 config (MPM worker):
---------------------------
<IfModule worker.c>
StartServers 1
MaxClients 10
MinSpareThreads 10
MaxSpareThreads 0
ThreadsPerChild 10
MaxRequestsPerChild 0
</IfModule>
Apache2 mod_python (.htaccess):
-------------------------------
PythonInterpPerDirective On
PythonOption "SiteName" "Heracles Test site"
PythonOption "SiteDescription" "Testing the framework!"
PythonOption "SiteVirtualPath" "/heracles/"
PythonOption "SiteViewPath" "/xxx/webapp/views/"
PythonOption "MySQLhost" "xxx"
PythonOption "MySQLuid" "arnaudsj"
PythonOption "MySQLpwd" "xxx"
PythonOption "MySQLdb" "test"
SetHandler python-program
PythonHandler heracles.site::handler
PythonDebug On
PythonAutoReload On
heracles.site.py:
-----------------
[...]
def handler(req):
"""
Standard mod_python handler code for Heracles Web Application
Framework
The SitePool is initialized based on Apache MPM setting
"""
global mySitePool
try:
mySite = mySitePool.get()
except NameError:
req.log_error("Initializing Heracles WAF at %s with %s thread
(s)" % (req.document_root(), apache.mpm_query(6)))
mySitePool = Pool(Constructor(Site, req), apache.mpm_query(6))
mySite = mySitePool.get()
return mySite(req)
mySitePool.put(mySite)
[...]
Cheers,
Sébastien
|