线程池&进程池

1
2
3
4
5
6
7
8
9
10
11
from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor

def fn(x):
for i in range(10):
print(x * i)

#10个线程的线程池
#可换为ProcessPoolExecutor
with ThreadPoolExecutor(10) as p:
for i in range(10):
p.submit(fn, i)