Apuntes_Python/02_conceptos/17_multiprocessing/d_ejemplo_multiprocessing_pool.py

26 lines
384 B
Python
Raw Normal View History

2022-12-24 22:41:20 -03:00
"""
Pool
"""
from multiprocessing import Pool
def cubo(numero):
return numero * numero * numero
if __name__ == "__main__":
numeros = range(10)
pool = Pool()
# map, apply, join, close
result = pool.map(cubo, numeros)
# pool.apply(cubo, numeros[0])
pool.close()
pool.join()
print(result)
"""
[0, 1, 8, 27, 64, 125, 216, 343, 512, 729]
"""