¿Existe un mapa paralelo simple basado en procesos para python?
Estoy buscando un mapa paralelo simple basado en procesos para python, es decir, una función
parmap(function,[data])
Que ejecutaría la función en cada elemento de [data] en un proceso diferente (bueno, en un núcleo diferente, pero AFAIK, la única manera de ejecutar cosas en núcleos diferentes en python es iniciar varios intérpretes), y devolver una lista de resultados.
¿Existe algo así? Me gustaría algo simple , por lo que un módulo simple sería bueno. Por supuesto, si no existe tal cosa, Me conformaré con una gran biblioteca: - /
1 answers
Parece que lo que necesitas es el método map en multiprocesamiento.Piscina():
Mapa (func, iterable [, chunksize])
A parallel equivalent of the map() built-in function (it supports only one iterable argument though). It blocks till the result is ready. This method chops the iterable into a number of chunks which it submits to the process pool as separate tasks. The (approximate) size of these chunks can be specified by setting chunksize to a positive integ
Por ejemplo, si desea asignar esta función:
def f(x):
return x**2
Para range (10), puedes hacerlo usando la función map () integrada:
map(f, range(10))
O usando un multiprocesamiento.Método del objeto Poll() map ():
import multiprocessing
pool = multiprocessing.Pool()
print pool.map(f, range(10))
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-11-09 23:21:58