[mod_python] RE: mod_python several magnitudes slower than PHP on my installation?

Graham Dumpleton graham.dumpleton at gmail.com
Sat May 19 21:39:13 EDT 2007


On 20/05/07, Martin _ <gzlist at googlemail.com> wrote:

> def handler(req):
>         buf = []
>         for i in xrange(1000):
>                 buf.append("Yeah\n")
>         req.write("".join(buf), 0)
>         return apache.OK

Or to avoid buffering in Python code and letting Apache buffering do
its thing instead use:

  def handler(req):
    for i in xrange(1000):
      req.write('Yeah\n, 0)
    return apache.OK

By default req.write() flushes data on each call, which using 'print'
with it would result in happening. Thus call req.write() directly and
supply second argument of 0 to avoid flushing.

Graham


More information about the Mod_python mailing list