multiprocessing模块与map方法

import time

from datetime import datetime

from multiprocessing.dummy import Pool as ThreadPool

from functools import partial

 

 

def add(x, y):

    print(datetime.now(), "enter add func...")

    time.sleep(2)

    print(datetime.now(), "leave add func...")

    return x+y

 

 

def add_wrap(args):

    add(*args)

    return

 

 

if __name__ == "__main__":

    pool = ThreadPool(4) # 池的大小为4

    print(pool.map(add_wrap, [(1,2),(3,4),(5,6)]))

    #close the pool and wait for the worker to exit

    pool.close()

    pool.join()

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-29
  • 2021-12-14
  • 2021-05-17
  • 2021-07-06
  • 2022-12-23
猜你喜欢
  • 2021-05-22
  • 2021-05-03
  • 2022-12-23
  • 2021-07-27
  • 2021-12-17
  • 2022-03-09
  • 2021-06-27
相关资源
相似解决方案