Kevin J. Smith
hockeysk8 at gmail.com
Tue Feb 21 09:22:27 EST 2006
Hi, I have a page controller that all handlers import with "from myapp.gui.pagecontroller import PageController". Each handler is a class derived from the PageController. In the page controller, I have attempted to set up a shared memory cache for all the controllers with code very similar to the following: #... import threading CACHE_LOCK = threading.Lock() cache = {} def _fillCache(): cache['one'] = '1' cache['two'] = '2' class PageController: # ... def __init__(self): #.... if not len(cache.keys()): CACHE_LOCK.acquire() _fillCache() CACHE_LOCK.release() #... However, I have discovered that this module is continually reimported because it ALWAYS calls the _fillCache() function despite all the handlers running within the same interpreter. I have upgraded to mod_python 3.2.7 noticing that in the change log there is a lot about fixing module import problems but my app is still behaving the same way. The flow of my app is that all requests are handled by a frontController handler (this is explicitly set in the httpd config) which, after checking the session and authentication and what-not and based on the request path, forwards the request onto one of my pageController handlers via util.redirect(). If I have followed Graham's notes about module importing correctly, the frontController and pageController classes would be imported via import_module() whereas the actual pageController module is imported via the regular python import mechanism. I have spent some time reading about the various "uniquenesses" of module importing within mod_python but it hurt my head slightly and I didn't know if most of it reflected the state of affairs in version 3.2.7. From reading Graham's page I don't believe I should have a problem with the PageController handler continually being reimported but it certainly appears to be doing just that. Can someone shed some light on what I may be doing wrong or a possible solution to setting up a shared cache within an interpreter? I know that if I run similar code outside of mod_python my cache design works fine. Cheers -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mm_cfg_has_not_been_edited_to_set_host_domains/pipermail/mod_python/attachments/20060221/c2fc83de/attachment.html
|