【发布时间】:2019-04-10 03:26:11
【问题描述】:
以下代码在 Python 3 中运行顺畅,但无法将其转换为 Python 2.7。
from multiprocessing import *
def func(path, filename, path_2):
#Things to do
for i in range(0,len(chr_names)): #len(chr_names) = 24
tuple_var.append((path, chr_names[i][0], chrom_sizes[i][0]))
cores = 4
with Pool(cores) as p:
p.starmap(func, tuple_var)
我收到以下错误。
python AttributeError: __exit__
我知道 Python 2.7 不支持星图。
我应该在 Python 2.7 中使用什么代码?
【问题讨论】:
-
那么,您是在问如何找到合适的 Pool.starmap 替代品吗?你能重构
func吗? -
是的,如果可能的话,还有一个关于如何在 func 中传递多个变量的示例。
标签: python multiprocessing pool starmap