【发布时间】:2020-03-26 05:11:25
【问题描述】:
我正在尝试使用 ProcessPoolExecutor 方法,但它失败了。 这是一个失败使用的例子(计算两个数字的大除数)。 我不明白错误是什么
def gcd(pair):
a, b = pair
low = min(a, b)
for i in range(low, 0, -1):
if a % i == 0 and b % i == 0:
return i
numbers = [(1963309, 2265973), (2030677, 3814172),
(1551645, 2229620), (2039045, 2020802)]
start = time()
pool = ProcessPoolExecutor(max_workers=2)
results = list(pool.map(gcd, numbers))
end = time()
print('Took %.3f seconds' % (end - start))
BrokenProcessPool:进程池中的一个进程在未来运行或挂起时突然终止。
【问题讨论】:
-
那里显示的解决方案不能解决我的问题。它仍然会引发错误
标签: python time concurrency subprocess concurrent.futures