A Flask app holds a reference to itself
See original GitHub issuefrom flask import Flask
import objgraph
def make_app():
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World!'
return app
def test():
myapp = make_app()
objgraph.show_backrefs([myapp], filename='backrefs.png', max_depth=6)
test()
Here’s what the produced reference graph looks like:
Is it the intended behavior? In our library a Flask app is created dynamically in a closure, and as a result it retains anything else that was created in that closure. We work around this by having a trampoline function and passing heavy objects as weakrefs, but it was still unexpected.
Environment
- Python version: 3.7.5
- Flask version: 1.1.2
- Werkzeug version: 1.0.1
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:7 (7 by maintainers)
Top Results From Across the Web
API — Flask Documentation (2.2.x)
The flask object implements a WSGI application and acts as the central object. It is passed the name of the module or package...
Read more >How to get a reference to a module inside the module itself?
The module reference can be found in the sys.modules dictionary. See the Python documentation · Share.
Read more >How To Handle Errors in a Flask Application - DigitalOcean
In this step, you'll create an application that has a few errors and run it without debug mode to see how the application...
Read more >1. Application Object — Flask API - GitHub Pages
The flask object implements a WSGI application and acts as the central object. It is passed the name of the module or package...
Read more >Developing Python Web Applications with Flask
It is strongly recommended to develop Python application under a virtual ... The from-import statement allows us to reference the Flask class directly...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@davidism and I discussed further and agreed to accept a fix for this, so I just merged #3762 after making some cleanups.
Thank you for the issue report and the PR!
The test that you added is now preventing me from implementing other legitimate things. I want to have a
self.json = JSONProvider(self)
assignment, but the test still fails. Composition like this is a very common pattern, and it would be meaningless to do it without theself
in this case. I’m very likely to remove the test to support that.