0
Ich versuche, einige Multiprocessing-Routine mit pathos Paket zu starten. Hier ist mein Code:Python Multiprocessing-Fenster und Jupyter
import multiprocessing as mp
import time
def square(x):
return x*x
if __name__=="__main__":
start_time = time.time()
p = mp.Pool(3)
function_results = p.map(square,[1,2,3]) #ordered
p.close()
print("--- %s seconds ---" % (time.time() - start_time))
Ich versuche es auf Win 10 laufen und mit Jupyter Notebook.
Der Code wird nicht ausgeführt und erzeugt den folgenden Fehler:
Process SpawnPoolWorker-2:
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\conda\conda\envs\tensorflow\lib\multiprocessing\process.py", line 252, in _bootstrap
self.run()
File "C:\Users\user\AppData\Local\conda\conda\envs\tensorflow\lib\multiprocessing\process.py", line 93, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\user\AppData\Local\conda\conda\envs\tensorflow\lib\multiprocessing\pool.py", line 108, in worker
task = get()
File "C:\Users\user\AppData\Local\conda\conda\envs\tensorflow\lib\multiprocessing\queues.py", line 337, in get
return ForkingPickler.loads(res)
AttributeError: Can't get attribute 'square' on <module '__main__' (built-in)>
Dieser Code lief auf Ubuntu 16.04 in Ordnung. Irgendwelche Vorschläge, wie man es repariert?
, welche Version von Python erwähnt verwenden Sie? – georgexsh
@georgexsh python 3.5 – user1700890
funktioniert für mich mit python3.5 in Windows 7 – georgexsh