i just learn about flask and requests. i want to get the number of working threads when i post request to the server. and i want to measure the time spent of the working threads. so this is my server and my client code:
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()
how do i know the number of working threads ? i just add threaded = True
on the server. i've been searching the answer and none of them answer my question. thanks in advance !