Python functools.partial是否不适用于multiprocessing.Pool.map?
我有简化的代码,如下所示:Python functools.partial是否不适用于multiprocessing.Pool.map?,python,multiprocessing,Python,Multiprocessing,我有简化的代码,如下所示: run = functools.partial(run, grep=options.grep, print_only=options.print_only, force=options.force) if not options.single and not options.print_only and options.n > 0: pool = multiprocessing.Pool(options.n) Map = pool.map el
run = functools.partial(run, grep=options.grep, print_only=options.print_only, force=options.force)
if not options.single and not options.print_only and options.n > 0:
pool = multiprocessing.Pool(options.n)
Map = pool.map
else: Map = map
for f in args:
with open(f) as fh: Map(run, fh)
try:
pool.close()
pool.join()
except NameError: pass
当我在单进程模式下运行它时,它工作得很好,但是失败了,出现了如下错误
TypeError: type 'partial' takes at least one argument
通过多处理模块与长调用堆栈混合在一起。发生什么事了
我正在使用python 2.6.1。谷歌告诉我这是一个;显然是在Py3k中固定的。这可能是由于
部分不可拾取
有一个。其作品使用:
from multiprocessing.dummy import Pool as ThreadPool
def executeFunction(server,function):
print "Server: %s and function: %s" % (server,function)
def executeParallel(servers,function, threads=10):
pool = ThreadPool(threads)
functionArguments=partial(executeFunction, function=function)
results = pool.map(functionArguments, servers)
pool.close()
pool.join()
return results
executeParallel(serverList, "Install")
web.archive链接现在也已失效