import multiprocessing
import time
def worker(n):
messages = [
"Processing data...",
"Running calculations...",
"Handling request...",
"Generating report...",
"Analyzing trends..."
]
msg = messages[n % len(messages)] # Assign different messages based on index
print(f"Worker {n}: {msg}")
time.sleep(1) # Simulate work
return f"Result from worker {n}"
if __name__ == "__main__":
numbers = [0, 1, 2, 3, 4]
with multiprocessing.Pool(processes=5) as pool:
results = pool.map(worker, numbers)
print(results)
https://cloud.google.com/blog/topics/systems/the-fifth-epoch-of-distributed-computing