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("执行结束")