我希望我的类方法可以并行运行,但是它只产生了一些错误,我无法解决。
我的代码如下:
import concurrent.futures as futures
samples = ['asfd', 'zxcv', 'asf', 'qwer']
class test:
def __init__(self, samples):
maturedb = {}
with futures.ProcessPoolExecutor() as exe:
for samplename, dResult in exe.map(self.make_readdb, samples):
maturedb[samplename] = dResult
print(maturedb)
def make_readdb(self, samplename):
return samplename, 1
test(samples)
如果我在Ubuntu机器上运行此代码,则会出现以下错误:
Traceback (most recent call last):
File "/usr/lib/python3.2/multiprocessing/queues.py", line 272, in _feedsend(obj)
_pickle.PicklingError: Can't pickle <class 'method'>: attribute lookup builtins.method failed
make_readdb
方法只是为了举例而简化的,但在实际代码中它是一个瓶颈,我需要将其并行化。