Ich führe die parallele Verarbeitung in Python unter Windows aus. Hier ist mein Code:python joblib Parallel unter Windows funktioniert nicht einmal "wenn __name__ == '__main__':" hinzugefügt wird
from joblib import Parallel, delayed
def f(x):
return sqrt(x)
if __name__ == '__main__':
a = Parallel(n_jobs=2)(delayed(f)(i) for i in range(10))
Hier ist die Fehlermeldung:
Process PoolWorker-2:
Process PoolWorker-1:
Traceback (most recent call last):
File "C:\Users\yoyo__000.BIGBLACK\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.4.3105.win-x86_64\lib\multiprocessing\process.py", line 258, in _bootstrap
self.run()
File "C:\Users\yoyo__000.BIGBLACK\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.4.3105.win-x86_64\lib\multiprocessing\process.py", line 114, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\yoyo__000.BIGBLACK\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.4.3105.win-x86_64\lib\multiprocessing\pool.py", line 102, in worker
task = get()
File "C:\Users\yoyo__000.BIGBLACK\AppData\Local\Enthought\Canopy\User\lib\site-packages\joblib\pool.py", line 363, in get
return recv()
AttributeError: 'module' object has no attribute 'f'
Wahrscheinlich möchten Sie eine return-Anweisung 'def f (x): return sqrt (x)' hinzufügen. – jotrocken
Nein, es ist das Gleiche. Ich lese auch irgendwo, dass Canopy die Dinge anders behandelt, also versuche ich 'sys.stdout.flush' nach' sqrt (x) 'hinzuzufügen, was auch nicht funktioniert – YKosinska
Nein, ist es nicht. Der Rückgabewert ist 'None', wenn Sie' return' nicht angeben. – jotrocken