[mod_python] [patch] make autoreload more useful

Martin Pool mbp at samba.org
Thu May 30 10:38:51 EST 2002


On 29 May 2002, Dustin Mitchell <dustin at ywlcs.org> wrote:

> 1. I'm not sure how gc interacts with this, but there was a time when you
> just couldn't get rid of a loaded module object.  All of the modules you
> delete will still reference each other in some sort of cycle. If they're not
> deleted you could very quickly end up with an enormous httpd process.

Here's a nickel; get a bigger computer :-)

> Even with gc, if there are any dangling references into one of the old
> modules (an atexit function? somewhere the Python standard libraries cache a
> reference?) then you're going to have a bloated httpd.

Using atexit functions within mod_python is pretty pointless, but your
general point about references held by system modules is correct.

If my code bloated that easily because of reloading modules then I
would be somewhat worried that something would cause it to happen
during production, and I'd feel I ought to investigate what was going
wrong.

You can always turn down MaxRequestsPerChild, or indeed turn off
autoreload.

I guess in general I believe that in development mode (as opposed to
release), correctness and developer productivity is more important
than performance.

In deployment mode, there shouldn't be any bloat because the .py files
won't change.  The cost is just stat'ing them each time, which is a
slight cost but not terrible.

> 2. One other difficulty: some modules actually *do* want to have global
> state.  For example, a MySQL interface should be able to establish its
> connection once and maintain that through many requests.  Perhaps there
> should be a mechanism for a module to say "don't remove me!", or at least
> "preserve the value of this variable".

As far as I can see, the only non-bogus use of persistence is
opportunistic caching.  Modules have to cope with losing their
persistent state because (a) requests are unpredictably spread across
Apache instances; (b) Apache can kill and restart children; (c)
relying on it is overly fragile; and (d) without a working reload
mechanism, the programmer will be completely restarting Apache at
intervals anyhow.

-- 
Martin 



More information about the Mod_python mailing list