我想让我的类方法并行运行,但它只会产生一些我无法解决的错误。 我的代码是:
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 machine中运行此代码,会出现如下错误:
^{pr2}$make_readdb方法只是简化为一个示例,但它是实际代码和 我需要让它平行。请帮忙。在
从docs:
试试ThreadPoolExecutor
更新
我又看了一遍代码,问题是函数
make_readdb
-是test
类的成员。你能重构这个功能吗?在相关问题 更多 >
编程相关推荐