import time from multiprocessing.pool import ThreadPool #注意ThreadPool不在threading模块下 from multiprocessing import Pool #导入进程池 def my_print(i): print("task start {}".format(i)) time.sleep(4) print("task end {}".format(i)) if __name__ == '__main__': tp = ThreadPool(10) # tp = Pool(10) for i in range(10): tp.apply_async(my_print,args=(i,)) tp.close() tp.join()
来源:CSDN
作者:ITROOKIEIS
链接:https://blog.csdn.net/qq_15256443/article/details/103634256