I'll start by mentioning I'm having a similar problem to this
(unanswered) thread:
http://groups.google.com/group/turbogears/browse_thread/thread/3b2e32154258c468/af1e64cdbd1fe412?lnk=gst&q=memory#af1e64cdbd1fe412

I have a Turbogears 2.1 webapp that creates and serves large .tar
files based on some files in the filesystem on that machine. Before I
started playing, the relevant controller function looked (roughly)
like this:

@expose()
def tar(self, **kwargs):
    tf = StringIO.StringIO()
    tar = tarfile.open(fileobj=tf, mode='w')

    toClose = []
    mtime = time.time()
    for filename in fileList:
        openFile = open(filename, 'r')
        imgData = openFile.read()
        openFile.close()

        theFile = StringIO.StringIO(imgData)
        toClose.append(theFile)

        tarinfo = tarfile.TarInfo(name=os.path.basename(filename))
        tarinfo.size = theFile.len
        tarinfo.mtime = mtime
        tar.addfile(tarinfo, fileobj=theFile)

    pylons.response.headers['Content-Type']  = 'application/x-tar;
charset=utf8'
    pylons.response.headers['Content-Disposition'] = \
            'attachment; filename="ImageRequest.tar"'

    tmp = tf.getvalue()
    tar.close()
    for f in toClose: f.close()
    tf.close()

    return tmp

I loop over a list of files, add them to a tar file, then return the
bytestream using StringIO. The problem is Turbogears is not releasing
the memory consumed in this operation. I have to say I'm a little
naive about the gritty details about this level of TG hacking, but I
tried adding an __after__ function to the controller that forces
garbage collection, but that didn't do anything...

import gc
def __after__(self, *args):
    gc.collect()

I would appreciate any help or suggestions, as this has been causing
some major problems!

Thanks,
Adrian

-- 
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en.

Reply via email to