Is there anyway i can have the below folder creation happen in parallel rather than iterate? I tried with multiprocessing and it seems to be not working. Any suggestions welcome.
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)
You're not using the pool.
Here's an example:
with multiprocessing.Pool(processes=n) as p:
p.map(foldercreation, ['A', 'B', 'C', 'D'])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.