Multiprocessing mit mehreren Argumenten für Funktion in Python 2.7

Ich versuche, umzusetzen multiprocessing, um die Geschwindigkeit eines Replikations-Schleife, aber nicht in Python27. Dies ist eine sehr vereinfachte version von meinem Programm, basierend auf die docs und die anderen Antworten hier SO (z.B. Python-multiprocessing-pool.anzeigen für multiple Argumente). Ich weiß, dass es eine Reihe von quesions auf multiprocessing, aber so weit ich habe nicht in der Lage, dieses Problem zu lösen. Hoffentlich habe ich nicht übersehen, etwas zu trivial.

Code

import itertools
from multiprocessing import Pool

def func(g, h, i):
    return g + h + i

def helper(args):
    args2 = args[0] + (args[1],)
    return func(*args2)

pool = Pool(processes=4)
result = pool.map(helper, itertools.izip(itertools.repeat((2, 3)), range(20)))
print result

Dies funktioniert bei Verwendung von map(...), aber nicht, wenn mit pool.map(...).

Fehlermeldung:

Process PoolWorker-3:
Traceback (most recent call last):
File "C:\Program_\EPD_python27\lib\multiprocessing\process.py", line 258, in _
bootstrap
self.run()
File "C:\Program_\EPD_python27\lib\multiprocessing\process.py", line 114, in run
self._target(*self._args, **self._kwargs)
File "C:\Program_\EPD_python27\lib\multiprocessing\pool.py", line 85, in worker
task = get()
File "C:\Program_\EPD_python27\lib\multiprocessing\queues.py", line 376, in get
return recv()
AttributeError: 'module' object has no attribute 'helper'
Schreibe einen Kommentar