python joblib并行在Windows上工作甚至“如果__name__ ==’__ ma
发布时间:2020-12-16 23:04:25 所属栏目:Python 来源:网络整理
导读:我在 Windows上运行 Python并行处理.这是我的代码: from joblib import Parallel,delayeddef f(x): return sqrt(x)if __name__ == '__main__': a = Parallel(n_jobs=2)(delayed(f)(i) for i in range(10)) 这是错误消息: Process PoolWorker-2: Process Po
我在
Windows上运行
Python并行处理.这是我的代码:
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)) 这是错误消息: Process PoolWorker-2: Process PoolWorker-1: Traceback (most recent call last): File "C:Usersyoyo__000.BIGBLACKAppDataLocalEnthoughtCanopyAppappdatacanopy-1.5.4.3105.win-x86_64libmultiprocessingprocess.py",line 258,in _bootstrap self.run() File "C:Usersyoyo__000.BIGBLACKAppDataLocalEnthoughtCanopyAppappdatacanopy-1.5.4.3105.win-x86_64libmultiprocessingprocess.py",line 114,in run self._target(*self._args,**self._kwargs) File "C:Usersyoyo__000.BIGBLACKAppDataLocalEnthoughtCanopyAppappdatacanopy-1.5.4.3105.win-x86_64libmultiprocessingpool.py",line 102,in worker task = get() File "C:Usersyoyo__000.BIGBLACKAppDataLocalEnthoughtCanopyUserlibsite-packagesjoblibpool.py",line 363,in get return recv() AttributeError: 'module' object has no attribute 'f' 解决方法
根据
this site,问题是Windows特定的:
我已经尝试过你的代码,它在Linux下运行完美. 不工作: 互动环节: >>> from math import sqrt >>> 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)) ... Process PoolWorker-1: Traceback (most recent call last): File "C:Python27libmultiprocessingprocess.py",in _bootstrap self.run() File "C:Python27libmultiprocessingprocess.py",in run self._target(*self._args,**self._kwargs) File "C:Python27libmultiprocessingpool.py",in worker task = get() File "C:Python27libsite-packagesjoblibpool.py",line 359,in get return recv() AttributeError: 'module' object has no attribute 'f' 工作方式: from math import sqrt def f(x): return sqrt(x) 互动环节: >>> from joblib import Parallel,delayed >>> from fun import f >>> if __name__ == '__main__': ... a = Parallel(n_jobs=2)(delayed(f)(i) for i in range(10)) ... >>> a [0.0,1.0,1.4142135623730951,1.7320508075688772,2.0,2.23606797749979,2.449489742783178,2.6457513110645907,2.8284271247461903,3.0] (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |