Python实现进程池和线程池的示例如下:
进程池:
from multiprocessing import Pool def f(x): return x*x
if name == 'main': with Pool(5) as p: print(p.map(f, [1, 2, 3]))
线程池:
from multiprocessing.pool import ThreadPool def f(x): return x*x
if name == 'main': with ThreadPool(5