python 多进程

import time
from multiprocessing import Pool
import numpy as np


def run(fn) :#将函数的输入换成列表或元组,即将多元输入打包
  a=fn[0]*fn[1]
  print (a)


if __name__ == "__main__" :
  startTime = time.time()
  testFL = a=np.array(list(range(100000000))).reshape(50000000,2)
  pool = Pool(10)#可以同时跑10个进程
  pool.map(run,testFL)
  pool.close()
  pool.join()   
  endTime = time.time()
  print ("time :", endTime - startTime)

将函数的输入换成列表或元组

posted @ 2022-08-19 22:58  luoganttcc  阅读(2)  评论(0编辑  收藏  举报