小编Avr*_*ham的帖子

Python并发.futures:ProcessPoolExecutor无法工作

我正在尝试使用 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))
Run Code Online (Sandbox Code Playgroud)

BrokenProcessPool:进程池中的进程在 future 正在运行或挂起时突然终止。

python concurrency time subprocess concurrent.futures

4
推荐指数
1
解决办法
5013
查看次数