多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
通过调用`multiprocessing.Pool`来创建进程池。 ```python """ @Date 2021/4/5 """ from multiprocessing import Pool import os, time, random def worker(msg): t_start = time.time() print('%s开始执行,进程号为%d' % (msg, os.getpid())) time.sleep(random.random() * 2) t_stop = time.time() print(msg, "执行完成,耗时%0.2f\n" % (t_stop - t_start)) if __name__ == '__main__': po = Pool(3) # 定义一个进程池 for i in range(0, 10): po.apply_async(worker, (i,)) print("--start--") po.close() po.join() print("--end--") ```