I must use library multiprocessing. Trying to run in parallel following loops:
tag=[] #get all model ID all_model_id=get_models_id() #I have a list of list liste_all_img_id=[] #I want to start multiprocessing here for i in range(0,len(all_model_id)): tag=get_tags(all_model_id[i][0]) # get_tags function return me a list #print(tag) for l in range(0,len(tag)): liste_all_img_id.append(get_images_id(tag[l][0],all_model_id[i][0])) #get_images_id function return me a list I tried this:
def funcs(start,end): tag=[] list_all_img_id=[] for i in range(start,end): tag=get_tags(all_model_id[i][0]) for l in range(0,len(tag)): list_all_img_id.append(get_images_id(tag[l][0],all_model_id[i][0])) return(list_all_img_id) from multiprocessing import Pool import multiprocessing def main(): all_model_id=get_models_id() len_all_model_id=len(all_model_id) div_total = int(len_all_model_id / 3) rest_div_total = len_all_model_id%3 t1 = multiprocessing.Process(target = funcs,name = "", args=(0, div_total)) t2 = multiprocessing.Process(target = funcs,name = "", args=(div_total, div_total*2)) t3 = multiprocessing.Process(target = funcs,name = "", args=(div_total*2, div_total*3 + rest_div_total + 1)) list_threads = [t1,t2,t3] for i in list_threads: i.start() for i in list_threads: i.join() if __name__ == "__main__": main() But :
I'm not sure main function is well defined
I don't know how to store my results