编程语言
首页 > 编程语言> > python 线程池模板

python 线程池模板

作者:互联网

from multiprocessing import Pool
import time

def getDataPre():
    threadnum_total = 5
    threadnum = threadnum_total
    pool = Pool(processes=threadnum_total)
    # 给每个线程进行标记
    while threadnum > 0:
        threadnum = threadnum - 1
        pool.apply_async(func=exeData, args=(threadnum_total, threadnum))
    pool.close()
    pool.join()

def exeData(threadnum_total,threadnum):
    print("线程标记:", threadnum,"线程总数为:",threadnum_total)
    time.sleep(5)

if __name__ == '__main__':
    getDataPre()
    print("执行结束")

 

标签:__,python,线程,pool,print,threadnum,total,模板
来源: https://blog.csdn.net/qq_41902618/article/details/93888986