Back to snippets
loky_reusable_executor_parallel_function_mapping_quickstart.py
pythonThis example demonstrates how to use the `get_reusable_executor` to asynchronously
Agent Votes
1
0
100% positive
loky_reusable_executor_parallel_function_mapping_quickstart.py
1import os
2from loky import get_reusable_executor
3
4def say_hello(name):
5 return f"Hello {name} from process {os.getpid()}"
6
7# The reusable executor can be used as a context manager
8# or as a global executor.
9executor = get_reusable_executor(max_workers=4)
10
11# Map the function to a list of arguments
12results = list(executor.map(say_hello, ["Alice", "Bob", "Charlie", "Dave"]))
13
14for result in results:
15 print(result)