Hi,
I am trying to get to the bottom of some leaking pyramid application.
Now, what I found out is the following simple example where the request
never get
cleaned up:
-------------------------------------------------------------------------------------------------------------------
from pyramid.config import Configurator
from pyramid.httpexceptions import HTTPFound
from pyramid.response import Response
import weakref
class Class1(object):
def __init__(self):
self.alot="------------------ ".join([str(a) for a in
range(0,10000)])
def __del__(self):
print "del object"
class View(object):
def __init__(self, context, request):
self.request = request
self.context = context
def __del__(self):
print "del view"
def test1(self):
url = self.request.url
return Response(body='hello world!', content_type='text/plain')
class ViewWeakref(object):
def __init__(self, context, request):
self._request = weakref.ref(request)
self.context = context
@property
def request(self):
return self._request()
def __del__(self):
print "del view"
def test1(self):
url = self.request.url
return Response(body='hello world!', content_type='text/plain')
class Root(object):
def __getitem__(self, name):
return Class1()
def getRoot(request):
return Root()
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
config = Configurator(root_factory=getRoot, settings=settings)
config.add_view(view=View, name="test1", attr="test1")
return config.make_wsgi_app()
-------------------------------------------------------------------------------------------------------------------
The application traverses the root object ("Root"), generates a context
("Class1") and
calls a view ("View.test1") for the context.
So the url to call this was for example "http://127.0.0.1:6543/class/test1"
What happens is __del__ functions are never called and and the application
consumes
more and more memory.
I think the important part is that the view is a "class" and it stores the
request as
class attribute. And in fact with a few modifications to store the request
as a weakref attribute
(class ViewWeakref) the application works allright and everything gets
cleaned up.
Now, I don't think this happens every time a view class is involved. My
original application
for example stores the request as view class atrribute (without using
weakref) and works allright.
But I suppose there are a few rare cases depending on how views are invoked
by pyramid
making it easy to run into leaking applications.
Has someone else run into this? Or do you explicitly cleanup after requests?
Arndt.
--
Arndt Droullier / DV Electric / www.dvelectric.de
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" 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/pylons-discuss?hl=en.