ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
通过调用`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--") ```