-
Notifications
You must be signed in to change notification settings - Fork 241
/
Copy pathflask_hello.py
47 lines (33 loc) · 889 Bytes
/
flask_hello.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import time
from pyinstrument import Profiler
try:
from flask import Flask, g, make_response, request
except ImportError:
print("This example requires Flask.")
print("Install using `pip install flask`.")
exit(1)
app = Flask(__name__)
@app.before_request
def before_request():
if "profile" in request.args:
g.profiler = Profiler()
g.profiler.start()
@app.after_request
def after_request(response):
if not hasattr(g, "profiler"):
return response
g.profiler.stop()
output_html = g.profiler.output_html()
return make_response(output_html)
@app.route("/")
def hello_world():
return "Hello, World!"
@app.route("/sleep")
def sleep():
time.sleep(0.1)
return "Good morning!"
@app.route("/dosomething")
def do_something():
import requests
requests.get("http://google.com")
return "Google says hello!"