- with ThreadPoolExecutor(max_workers=NUM_CONCURRENT) as executor:
- futures = {executor.submit(send_request, idx, url, data, headers) for idx, data in enumerate(data_list , 1)}
- to_exit = False
- for future_set in concurrent.futures.wait(futures, return_when=concurrent.futures.FIRST_EXCEPTION):
- for f in future_set:
- if f.exception():
- to_exit = True
- break
- if to_exit:
- break