赞
踩
def add(a: int, b: int):
print(a + b)
if __name__ == '__main__':
for i in range(300):
add(i, i + 1)
import multiprocessing
def add(a: int, b: int):
print(a + b)
if __name__ == '__main__':
pool = multiprocessing.Pool(2) # 两个进程执行
# pool = multiprocessing.Pool(multiprocessing.cpu_count()) # 全部cpu执行
for i in range(300):
pool.apply_async(func=add,args=(i, i + 1))
pool.close()
pool.join()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。