无论如何,我可以并行创建以下文件夹而不是迭代吗? 我尝试了多处理,但它似乎不起作用。欢迎任何建议。
import os
from time import sleep
import multiprocessing
def foldercreation(foldername):
target_dir = 'C:\Users\Myna\Desktop\Cisco'
os.mkdir(os.path.join(target_dir,foldername))
n=multiprocessing.cpu_count()
print(n)
with multiprocessing.Pool(processes=n) as p:
for i in ['A','B','C','D']:
foldercreation(i)
您没有使用池。
下面是一个示例:
with multiprocessing.Pool(processes=n) as p:
p.map(foldercreation, ['A', 'B', 'C', 'D'])