import threading def job(root_folder,my_list): for current,files,dirs in os.walk(root): my_list.extend(files) time.sleep(1) my_lists = [[],[],[]] my_folders = ["C:\\Windows","C:\\Users","C:\\Temp"] my_threads = [] for folder,a_list in zip(my_folders,my_lists): my_threads.append(threading.Thread(target=job,args=(folder,a_list) for thread in my_threads: thread.start() for thread in my_threads: thread.join() my_full_list = my_lists[0] + my_lists[1] + my_lists[2]
this way each thread simply modifies its own list and at the end merges all the individual lists
also, as indicated, gives a zero performance boost (actually, probably slower than not slicing it ...), you can get a performance gain by using multiprocessing instead ...
source share