Graham Dumpleton
grahamd at dscpl.com.au
Tue Aug 10 20:28:29 EDT 2004
What concerns me about mod_python (2.X, not sure about 3.X, haven't looked) and also mpservlets as well, is that the code to look to see if a module should be reloaded is of the form: if not klass or mtime > cached_mtime: Ie., reload the file if the file is newer. To my mind this is possibly wrong as it doesn't cater for the case where you might replace a file with an older version after you worked out the newer one didn't work and what you put back has a modification time in the past, not the future. For example: cp myservlet.py myservlet.py.backup # edit myservlet.py # exercise myservlet # find it loads and runs, but not desired result mv myservlet.py.backup myservlet.py The myservlet.py file now has a mtime older than the modified one you briefly ran so it will not reload automatically. You are forced to touch the file to update its mtime. You can also have problems when files are stored on NFS mounted directories and the two machines aren't time synced very well and changes are made on the NFS server. I would thus have though saying: if not klass or mtime != cached_mtime: would be more appropriate. Ie., if the mtime is different to cached mtime and not just newer. Comments? On Aug 10 15:27, "Nicolas Lehuen" <nicolas at lehuen.com> wrote: > > Subject: RE: [mod_python] Stopping Reimports > > Hi, > > I don't think your solution is so ugly... A few weeks ago I wrote about a > similar problem on this list, though my solution was to alter publisher.py > to change the way it builds module names (publisher.py version 1.36, line 67 > in mod_python 3.1.3)... Or, as Daniel Popowich wrote, you could use > mod_servlet (http://home.comcast.net/~d.popowich/mpservlets/) which does > correctly load modules. > > Note that you were in fact quite lucky to experience reimports, since some > people (including me, running mp 3.1.3 on Apache2 multithreaded on Windows) > experience a much worse behaviour : no reimport at all, e.g. /foo/index.py > would return the same page as /bar/index.py if /bar/index.py was touched > after /foo/index.py ! > > Regards, > > Nicolas Lehuen > > > -----Message d'origine----- > > De : mod_python-bounces at modpython.org > > [mailto:mod_python-bounces at modpython.org] De la part de Cu _ > > Envoyé : mardi 10 août 2004 13:47 > > À : mod_python at modpython.org > > Objet : [mod_python] Stopping Reimports > > > > mpy > > Hello, > > > > I'd like to know if there is some elegant way to deal with > > the [notice] mod_python: (Re)importing module 'index' with > > path set to [...] > > > > The mod_python.apache importing mechanism works correctly, > > the problem is, it keeps reimporting the same files. > > > > I don't think reimporting is the best solution for modules > > with same names but in different directories. > > > > It degrades performance with unneeded imports. > > > > Then, > > I try to use mod_python's sideeffect of not discarding > > variables when importing already loaded modules to cache > > frequently used data (If the module doesn't get reimported > > all the time, it's variables keep their values between > > subsequent requests). > > Every reimport causes the cached data to be reloaded. > > > > Also, it pollutes error_log :) > > > > My current "solution" is ugly, that's why I post here, maybe > > somebody will come up with something better. > > The idea is - if i have to load a module "my_module", which > > is at /path/to/my_files, don't load it as my_module, but as > > path_to_my_files_my_module That way, modules with same names > > will be assigned different names in sys.modules and won't get > > reloaded all the time. > > > > It's as using > > from path.to.my.files imort my_module as > > path_to_my_files_my_module instead of from path.to.my.files > > imort my_module > > > > Modules loaded with import_module are usually used by > > pointers, not by symbolic names so, as for me, it's ok to > > load it with a different name. > > > > my mod_python/apache.py import_module() now looks like this: > > > > def import_module(module_name, autoreload=1, log=0, path=None): > > ....... -- Graham Dumpleton (grahamd at dscpl.com.au)
|