flask 中获取请求的总时长
def create_app(config_name=None, app_name=None):
if not app_name:
app_name = __name__
app = Flask(app_name)
configure_app(app, config_name)
def configure_hook(app):
@app.before_request
def before_request():
g.start = time.time()
@app.after_request
def log_response(response):
# 接口请求耗时(毫秒)
diff = int((time.time() - g.start) * 1000)
print(diff)
return response
关注公众号「Python之禅」,回复「1024」免费获取Python资源