Python Flask-SQLAlchemy Memory Leaks Test - Python Flask-SQLAlchemy 内存泄漏测试
Python 3.6
pip install -r requirements.txt
MySQL
instance
folder under project root pathconfig.py
under instance
folder, add SQLALCHEMY_DATABASE_URI
src/models.py
to create table
python item_recorder.py
pip install memory_profile
@profile
def method_to_log():
pass
### If you need to generate memory figure
1. install package. `pip install matplotlib`
2. record memory changes. `mprof run item_recorder.py`
3. display image. `mprof plot mprofile_xxx.dat`, `xxx` like a timestamp auto generated
### If you need to record object growth
The `objgraph.growth` will show the increase in peak object counts since last call.
Default is Top 10.
1. install package. `pip install objgraph`
2. add code
```python
import objgraph
...# some code above...
objgraph.show_growth()
# If the program like a event-loop
# Try to catch `KeyboardInterrupt` event, like:
try:
pass
except KeyboardInterrupt as e:
objgraph.show_growth()
Uncomment the line in src/__init__.py
, or disable debug
mode.
# app.config.update(SQLALCHEMY_RECORD_QUERIES=False)