[mod_python] Output filters for large files

Robin Haswell me at robhaswell.co.uk
Fri Jun 22 07:05:49 EDT 2007

Hi there

I'm having issues writing an output filter that can handle large files.
My filter's primary purpose is to count the length of the output. Could
someone assist me please?

The code I have works very well except when a large file is passed
through it, at which point it eats up memory, probably equal to the size
of the file.

Any assistance would be much appreciated.

Here is my filter so far:

def outputfilter(filter):

    s = filter.read(4096)
    bytes = 0
    while s:
        bytes += len(s)
        s = filter.read(4096)

    if s is None:

Thanks in advance,

-Rob Haswell

More information about the Mod_python mailing list