【发布时间】:2017-06-02 12:34:34
【问题描述】:
我编写了一个简单的 Flask 应用程序来测试它的内存使用情况。
这里是代码。
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
with open("file.txt", "r") as fd:
text = fd.read()
return "Hello World!"
if __name__ == "__main__":
app.run(host="0.0.0.0")
file.txt 由该命令创建,大小为 50MB。
base64 /dev/urandom | head -c 50000000 > file.txt
用这个命令运行它:
python3 test.app
如果在不读取file.txt的情况下运行,内存使用量为18448KB。
如果运行并读取file.txt,内存使用量为18988KB。
这个文件是50MB,但是内存使用量只增加了540KB。我不明白 Python 是如何工作的。
【问题讨论】:
标签: python python-3.x flask