feat: 新增技能扩展 N3 一章相关示例源码
This commit is contained in:
19
code/newsletter/N3/futures_map_example.py
Normal file
19
code/newsletter/N3/futures_map_example.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from concurrent.futures import ProcessPoolExecutor
|
||||
|
||||
|
||||
def fib(n):
|
||||
if n <= 1:
|
||||
return n
|
||||
return fib(n - 1) + fib(n - 2)
|
||||
|
||||
|
||||
def main():
|
||||
n = [1, 3, 5, 10, 20]
|
||||
|
||||
with ProcessPoolExecutor(max_workers=4) as pool:
|
||||
result = pool.map(fib, n)
|
||||
print(list(result))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user