等待所有线程都执行完毕,获取结果
import concurrent.futures
def process_task(task):
tasks = [task1, task2, task3, ...]
with concurrent.futures.ThreadPoolExecutor() as executor:
futures = [executor.submit(process_task, task) for task in tasks]
done, _ = concurrent.futures.wait(futures)
for future in done:
try:
result = future.result()
except Exception as e:
及时处理结果
import concurrent.futures
def process_task(task):
tasks = [task1, task2, task3, ...]
with concurrent.futures.ThreadPoolExecutor() as executor:
futures = [executor.submit(process_task, task) for task in tasks]
for future in concurrent.futures.as_completed(futures):
try:
result = future.result()
except Exception as e: