# -*- coding: utf-8 -*-
import os
from functools import partial
from concurrent.futures import ProcessPoolExecutor
def fib(n):
if n < 3:
return 1
return fib(n - 1) + fib(n - 2)
executor = ProcessPoolExecutor(max_workers=1)
futures = []
for i in range(3,35):
futures += [(executor.submit(partial(fib, i)))]
out = [future.result() for future in futures if future.result is not None]
print(out)
输出结果:
[2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584,
4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811,
514229, 832040, 1346269, 2178309, 3524578, 5702887]
ProcessPoolExecutor time is: 0.7533223628997803
python ProcessPoolExecutor进程池
最新推荐文章于 2024-02-29 15:35:52 发布