frommultiprocessingimportPoolimporttimeimportosimportrandom**p=Pool(3)**defworker(msg):start_time=time.time()print("开始执行进程%d-----%s"%(msg,os.getpid()))time.sleep(random.random()*2)stop_time=time.time()print(msg,'耗费时间是%0.2f'%(stop_time-start_time))foriinrange(0,10):p.apply_async(worker,(i,))print("-----start-----")p.close()p.join()print("------END-------")为什么p=pool(3)如果写在defworker(msg)的上面,程序就会报错呢?如果写在defworker(msg)的下面就运行正常,网上没找到答案,求大神解答,感谢。
相关分类