# -*- coding: utf-8 -*-
from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor, as_completed
from loguru import logger
def run(number, string):
logger.info(f"{number} - {string}")
args = [
(1, 'a'),
(2, 'b'),
(3, 'c'),
]
with ThreadPoolExecutor(max_workers=8) as executor:
# submit
future_tasks = [executor.submit(run, number, string) for number, string in args]
for f in as_completed(future_tasks):
f.result()
# submit
future_tasks = {executor.submit(run, number, string): number for number, string in args}
for f in as_completed(future_tasks):
logger.info(future_tasks[f])
f.result()
# map
results = executor.map(run, [number[0] for number in args], [string[1] for string in args])
for result in results:
...