David Geller
dg at sponsera.com
Thu Feb 3 14:34:40 EST 2005
The way that python handles import is problematic for persistent interpreters such as implemented by mod_python. There doesn't, to me, seem any foolproof, *simple* way to solve reimportation issues in all circumstances, EXCEPT for what Daniel proposes, other than by restarting the server. It is such a pain to make some source changes, *think* you have reloaded affected modules, and then find out that the changes haven't taken effect! I have used this method for awhile now, and for debugging/development it seems to work (although I have some unexplained problems as I mentioned 11/20/2004 but never got a response on). It certainly is simple, and painless enough. Unexplained issue (from 11/20/2004): >I am setting a global dictionary (at the module level). Every time the >handler is executed, I check the global to see if it needs to be >initialized, and if so, I set it to some value. > >If MaxRequestsPerChild (apache directive) is 0, or a large number, you >get what you would expect: the global needs to be initialized the first >time after an apache restart, and seldom on subsequent requests. > >If I set it to 1, however, the same thing happens. I.e., it seems as if >the module is not being re-loaded for each request, which is what I >thought was the implication for MaxRequestsPerChild = 1. > >However, if I set MaxKeepAliveRequests to 1 as well, then the global >needs to be initialized on *alternate* requests. I.e., first time, yes. >2nd time, no, etc. > >Does anyone have an explanation for this? I am quite puzzled. > >(this is for MPM = prefork (as far as I know), on linux, apache 2.0.48, >mod_python 3.1.3, python 2.3.4) David Daniel Popowich wrote: > Jon-Pierre Gentil writes: > >>Argh! I wish that mod_python would check all loaded modules for changes >>as a flat rule, not as a tree... because currently it will only reload >>something if I touch the handler, because the reload code sees that the >>handler hasn't changed and does not bother checking the modules that the >>handler uses for changes. Might as well not even use mod_python.import() >>at all. >> >>Anyway, is there an option I can use to force the reload of the handler >>module each and every time a request is made? I am only needing this for >>debugging purposes, so I don't mind something that is a bit kludgey. >> >>Thank you! And please fix the import issue! > > > One brute force method which I employ during early stage development > and debugging is an apache configuration tweak. Assuming for the > moment you're using the prefork MPM: > > <IfModule prefork.c> > StartServers 8 > MinSpareServers 5 > MaxSpareServers 20 > MaxClients 150 > #MaxRequestsPerChild 1000 > # for debugging mod_python > MaxRequestsPerChild 1 > </IfModule> > > You'll notice where I comment out the default for MaxRequestsPerChild, > 1000, and replace it with 1. This allows each process to only serve > one request before being killed, so I get a fresh interpreter with > each request. When I'm ready for beta testing I switch back to 1000. > > Depending on your development box, this can be slow going, but you > will NEVER be burned by stale imports. > > Daniel Popowich > ----------------------------------------------- > http://home.comcast.net/~d.popowich/mpservlets/ > > > _______________________________________________ > Mod_python mailing list > Mod_python at modpython.org > http://mailman.modpython.org/mailman/listinfo/mod_python >
|