[mod_python] Leaking and cgi-handler

Gregory Trubetskoy grisha at modpython.org
Mon Jun 5 08:05:32 EST 2000


Sean - 

If you can find the source of the memory leak, please let me know what it
is, because I couldn't... :-(

The cgihandler when used with scripts not using cgi.py does not leak a
byte of memory. Unfortunately 98% of Python scripts out there start with
"import cgi".

A common misconception about Python and memory leaks is that it is
impossible to leak memory in Python. Python, just like any other language
allows you to allocate limitless memory, and in a persistent daemon-type
environment like Apache it shows.

Most likely the reason PyApache does not leak memory as bad is it resets
the interpeter between hits. This comes at a significant performance hit
since all the modules have to imported again, to the point where PyApache
isn't all that much faster than plain CGI.

My recomendation would to rewrite everything using "native" mod_python
handlers. They are simple (much simpler than CGI), fast and they do not
leak memory. You fears about them being unstable are unfounded, I think.

P.S. A skeleton content handler is described in the documentation.

--
  Gregory (Grisha) Trubetskoy
       grisha at modpython.org

On Mon, 5 Jun 2000, Sean True wrote:

> The same code runs under pyapache with a very modest memory leak (also
> documented for pyapache) of about 1K per page served.
> 
> I was a little unwilling to try switching to a more direct method of
> content handling under mod_python (creating a request handler for
> .phtml page) until the whole system was a little more stable. I'm in
> production under pyapache now, and I hate forking the code base.
> 
> Comments? Suggestions?
> 
> Does anyone have a skeleton content handler they would be willing to
> share, along with a corresponding .conf entry?
> 
> -- Sean




More information about the Mod_python mailing list