https://docs.python.org/3/library/concur...tor.submit Wrote:submit(fn, /, *args, **kwargs)
Schedules the callable, fn, to be executed as fn(*args **kwargs) and returns a Future object representing the execution of the callable
https://docs.python.org/3/library/concur...ecutor.map Wrote:map(func, *iterables, timeout=None, chunksize=1)
Similar to map(func, *iterables) except:
- The iterables are collected immediately rather than lazily;
- func is executed asynchronously and several calls to func may be made concurrently.
I used
ThreadPoolExecutor
as ProcessPoolExecutor
never works for mefrom concurrent.futures import ThreadPoolExecutor def func(value): return str(value) with ThreadPoolExecutor() as executor: results = [] for number in range(50): results.append(executor.submit(func, number)) print([result.result() for result in results]) with ThreadPoolExecutor() as executor: results = list(executor.map(func, range(50))) print(results)
Output:['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49']
['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49']