multi_thread_test.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # -*- coding: utf-8 -*-
  2. # @Time : 2022/3/3 16:13
  3. # @Author : MaochengHu
  4. # @Email : wojiaohumaocheng@gmail.com
  5. # @File : multi_thread_test.py
  6. # @Project : server_develop
  7. from multiprocessing import Pool
  8. from threading import Thread
  9. import os
  10. from server_utils.image_convert import path2base64
  11. from server_utils.read_properties import get_properties_dict
  12. import requests
  13. from multiprocessing import Process
  14. headers = {"Content-Type": "application/json"}
  15. # properties_dict = get_properties_dict()
  16. # inference_address = properties_dict.get("inference_address")
  17. import time
  18. num = 1
  19. t_time = time.time()
  20. def single_test(input_source=os.path.join(os.getcwd(), "../test_images/test1.jpg")):
  21. global num
  22. while True:
  23. request_url = "http://0.0.0.0:8080/predictions/yolov5"
  24. image_base64 = path2base64(input_source)
  25. payload = {"data": image_base64,
  26. "output_methods": str(["pd_xywh_json"]),
  27. "base64_bool": True}
  28. s_time = time.time()
  29. req = requests.post(url=request_url, data=payload)
  30. # print(eval(req.text))
  31. num += 1
  32. print(f"sub {time.time()-s_time} --- {num}")
  33. print(f"total {time.time() - t_time} -- {num}")
  34. if __name__ == '__main__':
  35. for i in range(120):
  36. t = Process(target=single_test)
  37. t.start()