我的代码如下。你知道吗
executor = concurrent.futures.ThreadPoolExecutor(max_workers=4)
for cj in self.parent_job.child_jobs:
executor.map(cj.runCommand())
def runCommand(自身): 操作系统(self.cmd\u行) 验证输出文件() ... 你知道吗
runCommand需要为所有子作业并行执行。同时,一次只能将一个子作业传递给runCommand。你知道吗
但是runCommand一次只能调用一次。但我需要同时调用所有子作业。任何帮助实现这一点都是非常感谢的
看看
executor.map
API:http://docs.python.org/dev/library/concurrent.futures.html#concurrent.futures.Executor.map 调用函数并将其结果传递给map
;,这就是代码只运行一次的原因。你知道吗您需要创建单独的函数,该函数将在方法
runCommand
的对象上调用,因为您不能将lambda x: x.runCommand()
(通常是lambda)作为参数传递给executor.map
。你知道吗要等到所有任务完成,您必须计算生成器
l
。所以你可以做w = list(l)
,w
将包含结果相关问题 更多 >
编程相关推荐