This makes the garbage collector unable to reclaim the memory used by a Flask app.
from flask import Flask
from raven.contrib.flask import Sentry
app = Flask(__name__)
for i in range(100):
The memory should stay stable, but it keeps growing because the signal stays connected.
flask: Use a weakref to hold onto the Sentry object when connecting t…
…o flask's got_request_exception signal
Trying to recall why I changed this to not be a weakref. I think it had something to do with referring to the client.
Anyways, going to merge this in, and if there's a future problem we'll figure it out
So I found out why you probably changed it in the first place.
Basically if the sentry client goes out of scope, the weakref will get removed. If one were to import the create_app example from above, the Sentry client would get configured, but would be removed from the got_request_exception receivers after app is returned. It would be nice if the docs reflected this detail, or weak=False was made an option instead of a default. Since the basic usage doesn't require calling the client ever, it's not obvious that it should still be bound to something.
I think we can just bind sentry to app or something so that we don't have to worry about persisting it. It really should be a weakref after all
On Tuesday, October 2, 2012 at 11:01 AM, James Bardin wrote:
Maybe the Sentry extensions could register itself in app.extensions['sentry'], although this would prevent configuring multiple Sentry for a single app.
In my code i do:
app.extensions['my-sentry'] = Sentry(app)
this way the client is not garbage collected until the app falls out of scope.
@rslinckx is app.extensions a standard thing?
Yes, as you can see there: http://flask.pocoo.org/docs/api/#flask.Flask.extensions
However as I said, this will prevent multiple Sentry to be registered to a single app (for example if i want to push some exceptions in sentry server A, and in some other cases some exceptions to sentry server B) then i can't do
app = Flask(name)
The Flask-SQLAlchemy extensions does store app.extensions['sqlalchemy'] = something, but then it implements the case where you want to connect to different databases itself so you don't need to register multiple flask-sqlalchemy extensions on a single app.
I would say that a first step is to just register sentry in the app.extensions and see later for the multi sentry case...