python自带线程池

时间:2023-03-08 15:45:23

1.  注意:  导包是:

    from multiprocessing.pool import ThreadPool  #线程池不在thrading中

2.  代码:

  from mutiprocessing.pool import ThreadPool

  def func(*args,**kwargs):

    print(args,kwargs)

  pool = ThreadPool(4)

  pool.apply_async(func,args = (1,2),kwds = {"name":'A'})

  pool.close()

  pool.join()

图例:

    python自带线程池