根据CPU内核创建多进程
from multiprocessing import Pool import psutil cpu_count = psutil.cpu_count(logical=False) #1代表单核CPU,2代表双核CPU pool = Pool(processes=cpu_count) for i in range(2, sht.range('A2').expand('table').rows.count+1): pool.apply_async(word_all,(i,)) # 使用元祖类型传参 pool.close() # 关闭进程池,不再接受新的进程 pool.join() # 主进程等待子进程结束