import requests from random import choice from threading import Thread, Lock, current_thread names = list(range(1, 9)) url = "http://localhost:5000/idc/" lock = Lock() def post(name: "str"): file = {"picture": (f"{name}.jpg", open(f"img/{name}.jpg", "rb"), "images/jpeg")} data = {"which": "face"} resp = requests.post(url, files=file, data=data) lock.acquire() print(current_thread().name, resp.json()) lock.release() def main(): for i in range(20): Thread(target=post, args=(choice(names),), name=f"th-{i + 1:02}").start() if __name__ == '__main__': main()