[mod_python] mod_python executing old versions of my code

Graham Dumpleton grahamd at dscpl.com.au
Thu Jan 26 02:00:01 EST 2006


On 26/01/2006, at 5:40 PM, Mike Looijmans wrote:

> When faced with the reload problem a few years ago, I created a 
> special "reload" request. The request would list all the .py[oc] files 
> in the script folder, and tries to unload or reload() each of them.

Will not work for mod_python.publisher in mod_python 3.2 and possibly
not at all in future versions of mod_python, but for mod_python <= 
3.1.4,
it is better to iterate over modules in sys.modules and if they contain
the attribute "__mtime__" set it to 0. By doing this, it will cause the
mod_python importer to reload it automatically the next time it is 
accessed.
By doing it this way, you don't expose yourself to issues that might 
arise
from mixing "apache.import_module()" and "reload()".

> As a result, the "main" modules as well as dependent modules will have 
> been reloaded or removed (At least, the ones that came from my project 
> - it would not make sense to unload modules like 'os').

Other projects should really be run in the context of a different 
interpreter
by specifying PythonInterpreter. On that basis, you would have to be 
selective
if above method used.

> So just sending "http://myhost/pu/reload" to the server would cause 
> the next request to get all new scripts.

This is only guaranteed to work if you are using mod_python on Win32 
platform.
It most definitely will not work with "prefork" on UNIX and usually not 
on
"worker" on UNIX. The reason the latter will not work reliably is that 
there
can be multiple Apache child processes and your request will only hit 
one of
those child processes. You would have to hit reload many times and even 
then
you wouldn't know for sure it had been done in all of the children.

> I even used this on the production server after uploading updates.
>
> --
> Mike Looijmans
> Philips Natlab / Topic Automation
>
>
> James Paige wrote:
>> Daniel Nogradi wrote:
>>>> I'm new to mod_python... so maybe I have missed something 
>>>> fundamental
>>>> here, but mod_python seems to be keeping several copies of my old 
>>>> code
>>>> in memory, so when I make changes and reload the page, sometimes I 
>>>> get
>>>>
>>>> my changes, and sometimes I get a seemingly-random version of the 
>>>> code
>>>> that I have already changed.
>>>>
>>>>
>>> You can also try setting the MaxRequestsPerChild apache directive to 
>>> 1, it
>>> worked for me very well. Initially I had the same problem like you, 
>>> but with
>>>
>>> MaxRequestsPerChild 1
>>>
>>> in the apache config file the problem is gone because every child 
>>> that loads
>>> your code dies after the request, so it doesn't stay anywhere.
>> That sounds like it would be an excellent workaround if I was using a
>> dedicated server that ran nothing but mod_python, but for a shared
>> server-- especially one on which I might not necessarily have root
>> access at all, that will not work.
>> ---
>> James Paige
>> _______________________________________________
>> Mod_python mailing list
>> Mod_python at modpython.org
>> http://mailman.modpython.org/mailman/listinfo/mod_python
>
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python



More information about the Mod_python mailing list