Dev HelpersOpen library
← Back

Map work with a thread pool

Map work with a thread pool. A self-contained example using the Python standard library.

Open this example in the interactive library

Source code

from concurrent.futures import ThreadPoolExecutor
with ThreadPoolExecutor(max_workers=2) as pool:
    print(list(pool.map(lambda n: n*n, [1, 2, 3])))

Sample output

[1, 4, 9]