我是python的新手,甚至更新的并行代码。我正在制作一个更大的脚本,但我试图简化问题。我正在使用joblib和copy_reg。执行我的脚本时,我没有收到所需的输出
p0...p1
但我得到了这个:
('p', <__main__.APR instance at 0x2dc9ea8>)
...
('p', <__main__.APR instance at 0x2dc9bd8>)
我真的很感激任何帮助!
#!/usr/bin/env python2
from joblib import Parallel, delayed
import copy_reg
import types
import multiprocessing
print'You are running python version', (sys.version)
if float('.'.join(((sys.version).split()[0]).split('.')[0:2]))<2.7:
print('Error: APR requires Python 2.7')
sys.exit()
def _pickle_method(method):
func_name = method.im_func.__name__
obj = method.im_self
cls = method.im_class
return _unpickle_method, (func_name, obj, cls)
def _unpickle_method(func_name, obj, cls):
for cls in cls.mro():
try:
func = cls.__dict__[func_name]
except KeyError:
pass
else:
break
return func.__get__(obj, cls)
class APR:
def __init__(self):
print('')
def equilibrate(window, prefix):
prefix='p'
print('p', window)
return
copy_reg.pickle(types.MethodType, _pickle_method, _unpickle_method)
windows=range(10)
if __name__ == "__main__":
this=APR()
num_cores = multiprocessing.cpu_count()
results = Parallel(n_jobs=num_cores)(delayed(this.equilibrate)(window) for window in windows)