Created
July 22, 2019 04:29
-
-
Save cocodrips/2d20239d8fa0a3630b0bc6437fc07dee to your computer and use it in GitHub Desktop.
flaskのrouteデコレータとほかのデコレータの併用
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
import time | |
from functools import wraps | |
from flask import Flask, Response | |
app = Flask(__name__) | |
def stop_watch(func): | |
@wraps(func) | |
def wrapper(*args, **kargs): | |
start = time.time() | |
result = func(*args, **kargs) | |
elapsed_time = time.time() - start | |
print(f"{func.__name__}は{elapsed_time}秒かかりました") | |
return result | |
return wrapper | |
@app.route('/') | |
@stop_watch | |
def home(): | |
time.sleep(3) | |
return Response(status=200) | |
if __name__ == '__main__': | |
logging.basicConfig() | |
logging.getLogger().setLevel(logging.DEBUG) | |
app.run(host='0.0.0.0', port=9001) |
Author
cocodrips
commented
Jul 22, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment