【发布时间】:2019-12-13 10:22:50
【问题描述】:
我只是了解烧瓶和请求。当我向服务器发布请求时,我想获取工作线程的数量。我想测量工作线程所花费的时间。所以这是我的服务器和我的客户端代码:
server.py
from flask import Flask
from flask import request
import time
from flaskthreads import AppContextThread
app = Flask(__name__)
@app.route("/", methods = ['GET', 'POST'])
def home():
timeout = time.time() + 10 # 5 minutes from now
while True:
test = 0
if test ==5 or time.time() > timeout:
break
return 'Hello', 200
def main():
app.run(host='0.0.0.0', threaded = True, debug = True)
if __name__ == "__main__":
main()
client.py
import os
import requests
import glob
import time
import base64
url = 'http://0.0.0.0:5000/'
def load_data():
os.chdir('./500_mb')
for image in glob.glob('*.jpg'):
with open(image, 'rb') as imageFile:
# image_s = base64.b64encode(imageFile.read())
image_s = {'file_image':open(image, 'rb')}
return image_s
def send_data():
start = time.time()
r = requests.post(url, files = load_data())
end = time.time()
print('client 1: {} ms'.format((end - start)*1000))
if __name__ == "__main__":
send_data()
我怎么知道工作线程的数量?我只是在服务器上添加threaded = True。我一直在寻找答案,但没有人回答我的问题。提前致谢!
【问题讨论】:
标签: python multithreading flask