简体   繁体   中英

How to parallelize a nested for loop of the Python?

This is a loop code I have for my final year project. It works fine but it executes slower. I need to make this faster. It is a nested for loop so is there a method to parallelize this code?

        for user in users.each():
            count += 1
            if not os.path.isdir("Facial_images/face_rec/train/User_" + str(count)):
                os.makedirs("Facial_images/face_rec/train/User_" + str(count))
            for i in range(20):
                DBHelper.download_user_photo("User_" + str(count) + "/" + str(i) + ".jpg")

This is a loop code I have for my final year project. It works fine but it executes slower. I need to make this faster. It is a nested for loop so is there a method to parallelize this code?

        for user in users.each():
            count += 1
            if not os.path.isdir("Facial_images/face_rec/train/User_" + str(count)):
                os.makedirs("Facial_images/face_rec/train/User_" + str(count))
            for i in range(20):
                DBHelper.download_user_photo("User_" + str(count) + "/" + str(i) + ".jpg")

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM